From 20bd99903ef5a4748bb2e45cfc4bf5a41b538f3d Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Sat, 3 Sep 2022 12:16:40 +0530 Subject: [PATCH] Close down track before closing subscriber peer connection (#981) * Close down track before closing subscriber peer connection * plural --- pkg/rtc/participant.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/rtc/participant.go b/pkg/rtc/participant.go index 605642c4b..7c121626c 100644 --- a/pkg/rtc/participant.go +++ b/pkg/rtc/participant.go @@ -662,7 +662,7 @@ func (p *ParticipantImpl) Close(sendLeave bool, reason types.ParticipantCloseRea } // remove all down tracks - var downTracksToClose []*sfu.DownTrack + downTracksToClose := make([]*sfu.DownTrack, 0, len(p.subscribedTracks)) for _, st := range p.subscribedTracks { downTracksToClose = append(downTracksToClose, st.DownTrack()) } @@ -740,6 +740,24 @@ func (p *ParticipantImpl) MaybeStartMigration(force bool, onStart func()) bool { return } p.params.Logger.Infow("closing subscriber peer connection to aid migration") + + // + // Close all down tracks before closing subscriber peer connection. + // Closing subscriber peer connection will call `Unbind` on all down tracks. + // DownTrack close has checks to handle the case of closing before bind. + // So, an `Unbind` before close would bypass that logic. + // + p.lock.Lock() + downTracksToClose := make([]*sfu.DownTrack, 0, len(p.subscribedTracks)) + for _, st := range p.subscribedTracks { + downTracksToClose = append(downTracksToClose, st.DownTrack()) + } + p.lock.Unlock() + + for _, dt := range downTracksToClose { + dt.CloseWithFlush(false) + } + p.TransportManager.SubscriberClose() }) p.lock.Unlock()