From d2e6cd150ee36013c5e15463209539fcc64cd194 Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Sat, 8 Mar 2025 11:13:35 +0530 Subject: [PATCH] Do not bind lock across flush which could take time (#3501) --- pkg/sfu/downtrack.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/sfu/downtrack.go b/pkg/sfu/downtrack.go index ba59770bd..670f02b28 100644 --- a/pkg/sfu/downtrack.go +++ b/pkg/sfu/downtrack.go @@ -1285,14 +1285,17 @@ func (d *DownTrack) Close() { // 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. func (d *DownTrack) CloseWithFlush(flush bool) { + d.bindLock.Lock() if d.isClosed.Swap(true) { // already closed + d.bindLock.Unlock() return } - d.bindLock.Lock() 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) // 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.bindLock.Lock() d.setBindStateLocked(bindStateUnbound) d.Receiver().DeleteDownTrack(d.SubscriberID())