Commit f8d2bb93 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Avoid deadlock in DelLocal.

parent 0c8df661
...@@ -211,30 +211,33 @@ func (up *rtpUpTrack) notifyLocal(add bool, track conn.DownTrack) { ...@@ -211,30 +211,33 @@ func (up *rtpUpTrack) notifyLocal(add bool, track conn.DownTrack) {
func (up *rtpUpTrack) AddLocal(local conn.DownTrack) error { func (up *rtpUpTrack) AddLocal(local conn.DownTrack) error {
up.mu.Lock() up.mu.Lock()
defer up.mu.Unlock()
for _, t := range up.local { for _, t := range up.local {
if t == local { if t == local {
up.mu.Unlock()
return nil return nil
} }
} }
up.local = append(up.local, local) up.local = append(up.local, local)
up.mu.Unlock()
up.notifyLocal(true, local) // do this asynchronously, to avoid deadlocks when multiple
// clients call this simultaneously.
go up.notifyLocal(true, local)
return nil return nil
} }
func (up *rtpUpTrack) DelLocal(local conn.DownTrack) bool { func (up *rtpUpTrack) DelLocal(local conn.DownTrack) bool {
up.mu.Lock() up.mu.Lock()
defer up.mu.Unlock()
for i, l := range up.local { for i, l := range up.local {
if l == local { if l == local {
up.local = append(up.local[:i], up.local[i+1:]...) up.local = append(up.local[:i], up.local[i+1:]...)
up.mu.Unlock() // do this asynchronously, to avoid deadlocking when
up.notifyLocal(false, l) // multiple clients call this simultaneously.
go up.notifyLocal(false, l)
return true return true
} }
} }
up.mu.Unlock()
return false return false
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment