From 41147e924f3ee27f8e8b6ea7690a47c8bd9f7222 Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Wed, 19 Oct 2022 05:02:41 +0530 Subject: [PATCH] Misc clean up (#1099) --- pkg/rtc/mediatracksubscriptions.go | 40 +++++++++++++----------------- pkg/rtc/transport.go | 4 +++ 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/pkg/rtc/mediatracksubscriptions.go b/pkg/rtc/mediatracksubscriptions.go index ac810b210..7b665b760 100644 --- a/pkg/rtc/mediatracksubscriptions.go +++ b/pkg/rtc/mediatracksubscriptions.go @@ -399,29 +399,23 @@ func (t *MediaTrackSubscriptions) downTrackClosed( if !willBeResumed { t.params.Telemetry.TrackUnsubscribed(context.Background(), subscriberID, t.params.MediaTrack.ToProto()) - // if the source has been terminated, we'll need to terminate all the subscribed tracks - // however, if the dest sub has disconnected, then we can skip - if sender == nil { - return - } - sub.GetLogger().Debugw("removing PeerConnection track", - "publisher", subTrack.PublisherIdentity(), - "publisherID", subTrack.PublisherID(), - "kind", t.params.MediaTrack.Kind(), - ) - if err := sub.RemoveTrackFromSubscriber(sender); err != nil { - if err == webrtc.ErrConnectionClosed { - // sub closing, can skip removing subscribedtracks - return - } - if _, ok := err.(*rtcerr.InvalidStateError); !ok { - // most of these are safe to ignore, since the track state might have already - // been set to Inactive - sub.GetLogger().Debugw("could not remove remoteTrack from forwarder", - "error", err, - "publisher", subTrack.PublisherIdentity(), - "publisherID", subTrack.PublisherID(), - ) + if sender != nil { + sub.GetLogger().Debugw("removing PeerConnection track", + "publisher", subTrack.PublisherIdentity(), + "publisherID", subTrack.PublisherID(), + "kind", t.params.MediaTrack.Kind(), + ) + + if err := sub.RemoveTrackFromSubscriber(sender); err != nil { + if _, ok := err.(*rtcerr.InvalidStateError); !ok { + // most of these are safe to ignore, since the track state might have already + // been set to Inactive + sub.GetLogger().Debugw("could not remove remoteTrack from forwarder", + "error", err, + "publisher", subTrack.PublisherIdentity(), + "publisherID", subTrack.PublisherID(), + ) + } } } } diff --git a/pkg/rtc/transport.go b/pkg/rtc/transport.go index 5a467f143..3d7567dc1 100644 --- a/pkg/rtc/transport.go +++ b/pkg/rtc/transport.go @@ -894,6 +894,10 @@ func (t *PCTransport) getOnNegotiationFailed() func() { } func (t *PCTransport) Negotiate(force bool) { + if t.isClosed.Load() { + return + } + if force { t.lock.Lock() t.debouncedNegotiate(func() {