Do not bind lock across flush which could take time (#3501)

This commit is contained in:
Raja Subramanian
2025-03-08 11:13:35 +05:30
committed by GitHub
parent 47896f50e3
commit d2e6cd150e
+7 -2
View File
@@ -1285,14 +1285,17 @@ func (d *DownTrack) Close() {
// 2. in case of session migration, participant migrate from other node, video track should // 2. in case of session migration, participant migrate from other node, video track should
// be resumed with same participant, set flush=false since we don't need to flush decoder. // be resumed with same participant, set flush=false since we don't need to flush decoder.
func (d *DownTrack) CloseWithFlush(flush bool) { func (d *DownTrack) CloseWithFlush(flush bool) {
d.bindLock.Lock()
if d.isClosed.Swap(true) { if d.isClosed.Swap(true) {
// already closed // already closed
d.bindLock.Unlock()
return return
} }
d.bindLock.Lock()
d.params.Logger.Debugw("close down track", "flushBlankFrame", flush) d.params.Logger.Debugw("close down track", "flushBlankFrame", flush)
if d.bindState.Load() == bindStateBound { isBound := d.bindState.Load() == bindStateBound
d.bindLock.Unlock()
if isBound {
d.forwarder.Mute(true, true) d.forwarder.Mute(true, true)
// write blank frames after disabling so that other frames do not interfere. // write blank frames after disabling so that other frames do not interfere.
@@ -1315,6 +1318,8 @@ func (d *DownTrack) CloseWithFlush(flush bool) {
d.params.Logger.Debugw("closing sender", "kind", d.kind) d.params.Logger.Debugw("closing sender", "kind", d.kind)
} }
d.bindLock.Lock()
d.setBindStateLocked(bindStateUnbound) d.setBindStateLocked(bindStateUnbound)
d.Receiver().DeleteDownTrack(d.SubscriberID()) d.Receiver().DeleteDownTrack(d.SubscriberID())