1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-26 02:25:58 +01:00

Avoid deadlock in DelLocal.

This commit is contained in:
Juliusz Chroboczek 2020-10-27 18:20:09 +01:00
parent 0c8df661b2
commit f8d2bb93e8

View file

@ -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
} }