Check for desired before clean up. (#1865)

Fix a potential race between needsCleanup checking and a re-subscribe
setting desired back to true.
This commit is contained in:
Raja Subramanian
2023-07-10 13:20:57 +05:30
committed by GitHub
parent e6f5f2f344
commit 1cb74b9e1b
+5 -1
View File
@@ -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()
}
}