Fix a race between delUpConn and addLocal.

We could call addLocal after the remote was closed, which
would cause the local connection to remain forever.

Thanks to Ludovic Rateau.
This commit is contained in:
Juliusz Chroboczek
2021-07-15 15:58:38 +02:00
parent 3d2089f40f
commit 9b8d868647
2 changed files with 18 additions and 1 deletions
+7
View File
@@ -5,6 +5,7 @@ import (
"io"
"log"
"math/bits"
"os"
"sync"
"sync/atomic"
"time"
@@ -461,6 +462,7 @@ type rtpUpConnection struct {
iceCandidates []*webrtc.ICECandidateInit
mu sync.Mutex
closed bool
pushed bool
replace string
tracks []*rtpUpTrack
@@ -500,6 +502,11 @@ func (up *rtpUpConnection) User() (string, string) {
func (up *rtpUpConnection) AddLocal(local conn.Down) error {
up.mu.Lock()
defer up.mu.Unlock()
// the connection may have been closed in the meantime, in which
// case we'd never get rid of the down connection
if up.closed {
return os.ErrClosed
}
for _, t := range up.local {
if t == local {
return nil