Do not remove from subscription map on unsubscribe. (#3002)
* Do not remove from subscription map on unsubscribe. Notes in line as to why. * Avoiding the extra check. It is fine to check under lock for clean up. It is done in other places. * comments
This commit is contained in:
@@ -391,15 +391,14 @@ func (m *SubscriptionManager) reconcileSubscription(s *trackSubscription) {
|
|||||||
if s.needsUnsubscribe() {
|
if s.needsUnsubscribe() {
|
||||||
if err := m.unsubscribe(s); err != nil {
|
if err := m.unsubscribe(s); err != nil {
|
||||||
s.logger.Warnw("failed to unsubscribe", err)
|
s.logger.Warnw("failed to unsubscribe", err)
|
||||||
} else {
|
|
||||||
// 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()
|
|
||||||
}
|
}
|
||||||
|
// do not remove subscription from map. Wait for subscribed track to close
|
||||||
|
// and the callback (handleSubscribedTrackClose) to set the subscribedTrack to nil
|
||||||
|
// and the clean up path to handle removing subscription from the subscription map.
|
||||||
|
// It is possible that the track is re-published before subscribed track is closed.
|
||||||
|
// That could create a new subscription and a duplicate entry in SDP.
|
||||||
|
// Waiting for susbcribed track close would ensure that the track is removed from
|
||||||
|
// the peer connection before re-published track is re-subscribed and added back to the SDP.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -414,15 +413,13 @@ func (m *SubscriptionManager) reconcileSubscription(s *trackSubscription) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.needsCleanup() {
|
|
||||||
m.lock.Lock()
|
m.lock.Lock()
|
||||||
if !s.isDesired() {
|
if s.needsCleanup() {
|
||||||
s.logger.Debugw("cleanup removing subscription")
|
s.logger.Debugw("cleanup removing subscription")
|
||||||
delete(m.subscriptions, s.trackID)
|
delete(m.subscriptions, s.trackID)
|
||||||
}
|
}
|
||||||
m.lock.Unlock()
|
m.lock.Unlock()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// trigger an immediate reconciliation, when trackID is empty, will reconcile all subscriptions
|
// trigger an immediate reconciliation, when trackID is empty, will reconcile all subscriptions
|
||||||
func (m *SubscriptionManager) queueReconcile(trackID livekit.TrackID) {
|
func (m *SubscriptionManager) queueReconcile(trackID livekit.TrackID) {
|
||||||
|
|||||||
Reference in New Issue
Block a user