From dc9f16f350bfdc99b1e696149cffd9ebd199f60a Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Mon, 30 Oct 2023 12:31:00 +0530 Subject: [PATCH] Do not block on down track close with flush. (#2201) * Do not block on down track close with flush. When publisher removes all subscribers, publisher side should not be blocked for long. With close with flush, it could happen if there a lot of bunch of subscribers. So, when is expected, run it in a goroutine like it is done in subscription manager. Not moving the entire `RemoveSubscriber` bit to subscription manager as there are two bits which are not tracked now - mime type - willBeResumed Those two would have to be tracked in track manager and notified to subscription manager so that it can act for that mine and if the track will be resumed or not. As that touch more parts and could get complicated, doing the simpler thing of cloning behaviour from subscription manager for now. * clean up * code readability --- pkg/rtc/mediatracksubscriptions.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/rtc/mediatracksubscriptions.go b/pkg/rtc/mediatracksubscriptions.go index 33ca4921f..15db1a8a3 100644 --- a/pkg/rtc/mediatracksubscriptions.go +++ b/pkg/rtc/mediatracksubscriptions.go @@ -304,14 +304,18 @@ func (t *MediaTrackSubscriptions) closeSubscribedTrack(subTrack types.Subscribed return } - dt.CloseWithFlush(!willBeResumed) - if willBeResumed { + dt.CloseWithFlush(false) + + // cache transceiver for potential re-use on resume tr := dt.GetTransceiver() if tr != nil { sub := subTrack.Subscriber() sub.CacheDownTrack(subTrack.ID(), tr, dt.GetState()) } + } else { + // flushing blocks, avoid blocking when publisher removes all its subscribers + go dt.CloseWithFlush(true) } }