Skip to content

Stop a voice rejoin offering two m-lines with the same msid - #7

Merged
davidtorcivia merged 1 commit into
masterfrom
fix/duplicate-msid-voice-rejoin
Aug 11, 2026
Merged

davidtorcivia merged 1 commit into
masterfrom
fix/duplicate-msid-voice-rejoin

Conversation

@davidtorcivia

Copy link
Copy Markdown
Owner

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. 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:failed breadcrumbs 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

removeVoiceSessionIfSame 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.

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, which is how this had to be diagnosed.

Behavior change

Keeping voiceMuteFlags across 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, removeSubscriberLocked returning it in deadTracks, and removeStaleRelaySenders leaving 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 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=msid should drop to zero. If the first line never appears, the reuse path is still unreachable.

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.
@davidtorcivia
davidtorcivia merged commit 5fd124c into master Aug 11, 2026
7 checks passed
@davidtorcivia
davidtorcivia deleted the fix/duplicate-msid-voice-rejoin branch August 11, 2026 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant