Roll back the sender when publishing fails after AddTrack - #1102
Merged
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
hiroshihorie
approved these changes
Aug 28, 2026
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Fixes #1098
When
_publishfailed afterAddTrackand negotiation had completed — deterministically on the audio frame-watcher timeout, but also on any negotiation failure after a successfulAddTrack— the catch only calledtrack.stop(). The sender stayed attached to the publisher PC and the server kept the publication, while the client had noLocalTrackPublication: mute was a no-op,isMicrophoneEnabled()lied, and a retry published a second track. Since capture was never stopped either, frames arriving after the timeout streamed live mic audio to the room.There is no remove-track signal for media tracks; the SFU only learns about a removal through renegotiation. So the failure path now does what
unpublishdoes: remove the sender from the publisher, renegotiate, and clear the track's transport/sender state. The backup-codec publish gets the same treatment, andunpublishnow clears the track's sender so a later publish attempt on the same track starts clean.Mirrors the fix Android shipped in livekit/client-sdk-android#986.
Test: a
TestAudioTracksubclass that throws fromstartWaitingForFrames()(after letting negotiation reach the server) reproduces the exact failure point headlessly; the test asserts no local publication or sender remains, and that a retry leaves exactly one track visible to a remote participant. Without the rollback it fails with two tracks on the remote and the sender still attached.Local server log for the test run, publisher side: