Cancel publication jobs when preparing for a full reconnect - #999
Open
adrian-niculescu wants to merge 1 commit into
Open
Cancel publication jobs when preparing for a full reconnect#999adrian-niculescu wants to merge 1 commit into
adrian-niculescu wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: f961eb3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
adrian-niculescu
force-pushed
the
fix-reconnect-publication-job-leak
branch
5 times, most recently
from
August 13, 2026 13:45
610cf41 to
2ec04f0
Compare
adrian-niculescu
force-pushed
the
fix-reconnect-publication-job-leak
branch
from
August 13, 2026 14:02
2ec04f0 to
f961eb3
Compare
adrian-niculescu
marked this pull request as ready for review
August 13, 2026 14:18
adrian-niculescu
requested review from
MaxHeimbrock,
davidliu and
xianshijing-lk
as code owners
August 13, 2026 14:18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
prepareForFullReconnect()clears the track publications, so theunpublishTrack()calls inrepublishTracks()can't find the old publications and never cancel their jobs. Each full reconnect therefore leaks the feature collector of every published audio track, which keeps running and sendsUpdateLocalAudioTrackwith the sid of the replaced publication whenever the track's features change.Cancel the jobs when preparing for the reconnect. Republishing creates fresh jobs for the new publications.
The reconnect coroutine,
publishAudioTrack, andunpublishTrackcan all touch the jobs map from different threads, so job registration and draining are serialized: retiring paths remove the publication fromtrackPublicationsbefore draining its job, and registration re-checks under the same monitor that the publication is still current. That re-check alone can't tell a stale publish from a live one, since a publish accepted on the old session can resume after the teardown and re-insert its publication. Acceptances are therefore validated against a full reconnect epoch: each signal connection captures the epoch current when it opens, aTrackPublishedresponse carries its connection's epoch, preparing a full reconnect advances the epoch, and the collector only starts when the acceptance's epoch is still current. Closing the old connection doesn't join an in-flight response handler, so aTrackPublishedthat already passed the connection guard can complete after the close and the epoch advance; carrying the epoch with the response keeps that acceptance attributed to the old session. A publish accepted by the replacement session registers normally, and soft reconnects preserve publishes without advancing the epoch.Split out of #987, which was closed since its main feature turned out to be unnecessary (#375). Five regression tests pin the behavior: a features change after a full reconnect produces exactly one update, a publish completing across reconnect preparation sends no stale-sid updates, an acceptance delivered by the old session after preparation is treated as stale, a publish accepted by the replacement session keeps reporting feature changes, and feature updates flow unaffected across a soft reconnect.