Repository navigation
Conversation
…k fails to republish
There was a problem hiding this comment.
Devin Review found 2 potential issues.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
| } catch (error, stackTrace) { | ||
| logger.warning('Failed to re-publish ${track.source} track ${track.sid}: $error', error, stackTrace); |
There was a problem hiding this comment.
🔴 Camera restarts after Unpublish all
While microphone republish waits, Unpublish all misses the camera in rePublishAllTracks’s private snapshot. After the microphone times out, the loop publishes the camera despite the user’s stop request.
Learn more
The example app’s Unpublish all control calls unpublishAllTracks() after confirmation and remains available on the room page during reconnect. unpublishAllTracks only sees entries in trackPublications. rePublishAllTracks clears that map before waiting for the first publish, so an unpublish request during that wait never reaches the queued camera. Before this change, a timeout on the first track stopped the loop, leaving the queued camera unpublished. Now the loop attempts the camera after the timeout, without honoring the completed Unpublish all request.
Example: A participant reconnects with microphone and camera enabled. While the microphone waits for its publish response, they confirm Unpublish all. The microphone times out, but the server answers the camera’s publish request, so video resumes.
Recommended fix: Make unpublishAllTracks() cancel pending reconnect publications as well as registered publications. Check that cancellation before attempting each queued track and reconcile any publish already in flight. Test Unpublish all during a pending microphone republish followed by a timeout, and assert that the camera never publishes.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
The race is real, but it isn't new. On main the same thing happens whenever the microphone republish succeeds: rePublishAllTracks() has already cleared trackPublications, so unpublishAllTracks() during the wait can't see the queued camera. This PR only extends it to the case where the first republish fails. Cancelling queued republishes needs a cancellation hook in rePublishAllTracks(), which seems better as its own change.
Fixes #1274. Alternative to #1279: this also republishes the tracks after the failing one.
Problem
After a full reconnect, one track that fails to republish leaves that track and every track after it unpublished, and the room never emits
RoomReconnectedEvent. Remote track settings are not re-sent and listeners are not notified, so an app waiting for the reconnect stays in its reconnecting state.#1274 shows it on Android and iOS. On web, with 2.13.2 on LiveKit Cloud, the trigger is a third one: after a full reconnect the microphone's
AddTrackRequestgets no answer within the publish timeout, soEngine.addTrackthrowsTrackPublishException(engine.dart:342in 2.13.2, line 407 onmain). Two production sessions, client time relative to the full reconnect:The web stack ends at the
Engine.addTracktimeout. The app had no publish of its own in flight, so we infer the caller wasrePublishAllTracks(). In session 1 the unanswered publish offer then made every later resume fail, which #1301 fixes.Cause
The
EngineRestartedEventhandler inRoomawaitslocalParticipant.rePublishAllTracks()without a try/catch.rePublishAllTracks()clearstrackPublications, then republishes each track in turn, also without a catch. The first failure ends the loop, then escapes the handler before it re-sends track settings, emitsRoomReconnectedEventand notifies listeners.Fix
rePublishAllTracks()catches a failure per track, logs it as a warning, and moves on to the next track.EngineRestartedEventhandler.handleSignalRestarted.The JS SDK republishes tracks in parallel (
Promise.allinLocalParticipant.republishAllTracks), so one failure doesn't stop the others, andhandleSignalRestartedcatches the error, logs it and carries on. Dart republishes one track at a time, so the catch goes per track to get the same result. #1279 catches in the handler only, which, as its description notes, still leaves the tracks after the failing one unpublished.Testing
test/core/room_e2e_test.dart, "full reconnect / republish failures do not stop other tracks or the reconnection": two local audio tracks whose republish throws.RoomReconnectedEventis emitted and the second republish is still attempted. It fails onmainand passes here.ROOM_DELETEDleave while a republish is pending. It fails without the check (RoomReconnectedEventfires afterRoomDisconnectedEvent) and passes here.Notes
mainbehave the same.