From a45a5e50cd4a2bc1431188e6d6ca51b2d74225af Mon Sep 17 00:00:00 2001 From: Jackie Li Date: Fri, 13 Jun 2025 06:31:00 +0100 Subject: [PATCH] fix track.unbind panic (#634) Fix #633 Here the signalCh could have been closed by another goroutine, we should use returned signalCh from `track.removeActivePeerConnection()` to close the channel. Actually, I don't know why we need to close the signalCh, we're using it to send over the doneCh, why ever close it? --- track.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/track.go b/track.go index d3d2865..bc06be8 100644 --- a/track.go +++ b/track.go @@ -203,8 +203,10 @@ func (track *baseTrack) bind(ctx webrtc.TrackLocalContext, specializedTrack Trac encodedReader.Close() // When there's another call to unbind, it won't block since we remove the current ctx from active connections - track.removeActivePeerConnection(ctx.ID()) - close(signalCh) + signalCh := track.removeActivePeerConnection(ctx.ID()) + if signalCh != nil { + close(signalCh) + } if doneCh != nil { close(doneCh) }