Skip to content

Commit

Permalink
webrtc: fix crash during client disconnection (#1482)
Browse files Browse the repository at this point in the history
OnConnectionStateChange of pion/webrtc is not thread safe. Add a mutex
to make it thread safe.
  • Loading branch information
aler9 committed Feb 21, 2023
1 parent 8ffdd9c commit 108c9d2
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/core/webrtc_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 108c9d2

Please sign in to comment.