webrtc: fix crash during client disconnection (#1482) (#1501)

OnConnectionStateChange of pion/webrtc is not thread safe. Add a mutex
to make it thread safe.
This commit is contained in:
Alessandro Ros 2023-02-21 23:35:22 +01:00 committed by GitHub
parent 8ffdd9c80e
commit 64b8fd3554
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 0 deletions

View File

@ -345,8 +345,12 @@ func (c *webRTCConn) runInner(ctx context.Context) error {
pcConnected := make(chan struct{})
pcDisconnected := make(chan struct{})
pcClosed := make(chan struct{})
var stateChangeMutex sync.Mutex
pc.OnConnectionStateChange(func(state webrtc.PeerConnectionState) {
stateChangeMutex.Lock()
defer stateChangeMutex.Unlock()
select {
case <-pcClosed:
return