From 1cb74b9e1b4f9c0f05b11d103940b464bf114584 Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Mon, 10 Jul 2023 13:20:57 +0530 Subject: [PATCH] Check for desired before clean up. (#1865) Fix a potential race between needsCleanup checking and a re-subscribe setting desired back to true. --- pkg/rtc/subscriptionmanager.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/rtc/subscriptionmanager.go b/pkg/rtc/subscriptionmanager.go index fbf83dd7..1ed7d3f8 100644 --- a/pkg/rtc/subscriptionmanager.go +++ b/pkg/rtc/subscriptionmanager.go @@ -369,6 +369,7 @@ func (m *SubscriptionManager) reconcileSubscription(s *trackSubscription) { // successfully unsubscribed, remove from map m.lock.Lock() if !s.isDesired() { + s.logger.Debugw("unsubscribe removing subscription") delete(m.subscriptions, s.trackID) } m.lock.Unlock() @@ -389,7 +390,10 @@ func (m *SubscriptionManager) reconcileSubscription(s *trackSubscription) { if s.needsCleanup() { m.lock.Lock() - delete(m.subscriptions, s.trackID) + if !s.isDesired() { + s.logger.Debugw("cleanup removing subscription") + delete(m.subscriptions, s.trackID) + } m.lock.Unlock() } }