mirror of
https://github.com/livekit/livekit.git
synced 2026-04-01 15:15:45 +00:00
Another case of duplciate tracks in SDP. During migration (if both publisher and subscriber migrate), subscriber could attach the remote track of the publisher. But, while that is happening, publisher could migrate into the node and close the remote media track. This was causing subscriber to switch from attaching to remote media track -> attaching to local media track. But, as remote media track was closed while add subscription was happening, the subscriber is removed without subscription manager being aware of it. So, the subscription manager's reconcile and the remove subscriber is racing and when subscription manager re-subscribes, caching has not run yet and that creates a duplicate. Delay removing subscribed track till after caching is done. That means, even if the reconciler runs, it will get an `errAlreadySubscribed` error and it will force it to reconcile again. By the time the subscribed track is deleted from the subscriptions map, caching is done.