Repository navigation
Stop a voice rejoin offering two m-lines with the same msid - #7
Merged
Merged
Conversation
A voice relay track is named after its owner: voice-<participantId> and voice-stream-<participantId>. CreateVoiceRelayTrack reuses that track when the owner's mic reconnects, so subscribers do not accumulate a dormant sender per rejoin. removeVoiceSessionIfSame deleted the VoiceLocalTracks entry that the reuse lookup reads, without detaching the senders still bound to the old track, so the reuse path was unreachable: every voice reconnect built a second TrackLocalStaticRTP carrying the same msid and added it to peers that still held the first. "Rebound voice relay" does not appear once in a 4566-line session log. The resulting renegotiation offer carries two identical a=msid lines. Chrome fails SetRemoteDescription with "Duplicate a=msid lines detected" and Safari with the same SyntaxError, so neither sends an answer. Pion v4 cannot roll back a local offer, so that subscriber stays in HaveLocalOffer and the stable-state guard in tryAddTrackAndRenegotiate defers every later track add against it, with no flush point ever reached. It receives no further relay tracks until its peer connection is rebuilt. Firefox accepts the duplicate, so on 2026-08-11 the one participant on Firefox kept hearing the room while the participants on Chrome and Safari stopped hearing each other. removeVoiceSessionIfSame now keeps VoiceLocalTracks and voiceMuteFlags. Both are keyed to the participant's membership in the room rather than to one voice peer connection, so a mic reconnect rebinds the existing track and needs no renegotiation at all. removeSubscriberLocked, which runs on a confirmed leave, returns the voice relay in deadTracks so removeSendersForTracks detaches it from the remaining subscribers, as it already did for webcam and screen share. It previously deleted the map entry and left those senders bound to a dead track. removeStaleRelaySenders detaches any sender whose track carries the same ID and stream ID as an incoming track, on both relay add paths. That holds for voice, webcam and screen share however the relay was rebuilt. Keeping voiceMuteFlags across a voice session teardown is a behavior change. An admin mute now survives the muted participant bouncing their voice peer connection; it previously did not, which let a client clear its own mute by reconnecting. Two relay loops can now write to one shared local track across a rejoin, so relayTrackLoop re-checks its done channel between the read and the write. Cancellation normally arrives while the goroutine is parked in Read, which the top-of-loop check cannot catch, and that last packet would otherwise land mid-stream in the replacement's sequence numbers under one SSRC. Subscriber.watchOfferAnswered reports a renegotiation offer still unanswered after 10 seconds. The wedged state is otherwise visible only as a missing "renegotiation answer" line. Tests verify that the voice relay track survives a voice session teardown and is retired on leave, that removeSubscriberLocked returns it in deadTracks, and that removeStaleRelaySenders leaves exactly one a=msid line for the relay in the offer that follows. Two tracks with matching IDs attached to one peer connection produce two such lines, which is what the guard removes. The mute gate test now asserts the flag survives a teardown and is cleared by departure.
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.
A voice relay track is named after its owner:
voice-<participantId>andvoice-stream-<participantId>.CreateVoiceRelayTrackreuses that track when the owner's mic reconnects, so subscribers do not accumulate a dormant sender per rejoin.removeVoiceSessionIfSamedeleted theVoiceLocalTracksentry that the reuse lookup reads, without detaching the senders still bound to the old track, so the reuse path was unreachable: every voice reconnect built a secondTrackLocalStaticRTPcarrying the same msid and added it to peers that still held the first. "Rebound voice relay" does not appear once in a 4566-line session log.The resulting renegotiation offer carries two identical
a=msidlines. Chrome failsSetRemoteDescriptionwith "Duplicate a=msid lines detected" and Safari with the sameSyntaxError, so neither sends an answer. Pion v4 cannot roll back a local offer, so that subscriber stays inHaveLocalOfferand the stable-state guard intryAddTrackAndRenegotiatedefers every later track add against it, with no flush point ever reached. It receives no further relay tracks until its peer connection is rebuilt.Firefox accepts the duplicate. That is the asymmetry behind the reported symptom on 2026-08-11: the participant on Firefox kept hearing the room while the participants on Chrome and Safari stopped hearing each other. Three
reneg:failedbreadcrumbs in that session, from Chrome/151, Chrome/149 and Safari/26, and none from Firefox/155. At 21:53:38 the Firefox subscriber answered the renegotiation and the Safari subscriber never did, then never answered again.Changes
removeVoiceSessionIfSamekeepsVoiceLocalTracksandvoiceMuteFlags. Both are keyed to the participant's membership in the room rather than to one voice peer connection, so a mic reconnect rebinds the existing track and needs no renegotiation at all.removeSubscriberLocked, which runs on a confirmed leave, returns the voice relay indeadTrackssoremoveSendersForTracksdetaches it from the remaining subscribers, as it already did for webcam and screen share. It previously deleted the map entry and left those senders bound to a dead track.removeStaleRelaySendersdetaches any sender whose track carries the same ID and stream ID as an incoming track, on both relay add paths. That holds for voice, webcam and screen share however the relay was rebuilt.Two relay loops can now write to one shared local track across a rejoin, so
relayTrackLoopre-checks its done channel between the read and the write. Cancellation normally arrives while the goroutine is parked inRead, which the top-of-loop check cannot catch, and that last packet would otherwise land mid-stream in the replacement's sequence numbers under one SSRC.Subscriber.watchOfferAnsweredreports a renegotiation offer still unanswered after 10 seconds. The wedged state is otherwise visible only as a missing "renegotiation answer" line, which is how this had to be diagnosed.Behavior change
Keeping
voiceMuteFlagsacross a voice session teardown means an admin mute now survives the muted participant bouncing their voice peer connection. It previously did not, which let a client clear its own mute by reconnecting. Departure still clears the flag, so a genuine rejoin starts unmuted.Tests
New tests cover the voice relay track surviving a voice session teardown and being retired on leave,
removeSubscriberLockedreturning it indeadTracks, andremoveStaleRelaySendersleaving exactly onea=msidline for the relay in the offer that follows. Two tracks with matching IDs attached to one peer connection produce two such lines, which is what the guard removes. The existing mute gate test now asserts the flag survives a teardown and is cleared by departure.Acceptance signal after deploy
"Rebound voice relay" should start appearing in the server log, and
Duplicate a=msidshould drop to zero. If the first line never appears, the reuse path is still unreachable.