-
Notifications
You must be signed in to change notification settings - Fork 153
Fixed full reconnect republish racing concurrent publishes of the same track #990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
adrian-niculescu
wants to merge
1
commit into
livekit:main
from
adrian-niculescu:fix/reconnect-republish-publish-race
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "client-sdk-android": patch | ||
| --- | ||
|
|
||
| Fixed full reconnect republish racing concurrent publishes of the same track, which could leave the mic published but silent or silently unpublished. |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Screen share that the user ended during a reconnect is restarted, which can crash the app
A screen share that the user already ended is forcibly restarted (
startCapture()atlivekit-android-sdk/src/main/java/io/livekit/android/room/participant/LocalParticipant.kt:1409) while restoring tracks after a reconnect, so the app can crash or resume a dead screen share.Impact: If the user stops screen sharing while the connection is being re-established, the app may crash or end up publishing a broken screen share, and other tracks are not restored.
restartTrackIfStopped does not distinguish screencast tracks, whose projection and foreground service are already gone
When the user stops screen capture through the system UI,
MediaProjectionCallbackinvokesLocalScreencastVideoTrack.stop(), which stops the capturer, setsenabled = falseand shuts down the capture foreground service (livekit-android-sdk/src/main/java/io/livekit/android/room/track/LocalScreencastVideoTrack.kt:186-190). The participant's ownonStopcallback callsunpublishTrack, which early-returns during a full reconnect becausetrackPublicationswas already cleared byprepareForFullReconnect(livekit-android-sdk/src/main/java/io/livekit/android/room/participant/LocalParticipant.kt:996-1001).The accumulated republish snapshot therefore still holds an unmuted screen share publication whose track is disabled.
republishTrackthen callsrestartTrackIfStopped, whoseis LocalVideoTrackbranch matchesLocalScreencastVideoTrackand callsstart()+startCapture(). The media projection permission result has already been consumed and the foreground service is stopped, soScreenCapturerAndroid.startCapturefails (throwing on modern Android). The exception escapesrepublishTracks()intoRoom.onPostReconnectand theRTCEnginereconnect coroutine, which has no exception handler (livekit-android-sdk/src/main/java/io/livekit/android/room/RTCEngine.kt:213,:693), aborting the republish of any remaining tracks. AGENTS.md also forbids crashing consumer code via unchecked exceptions.Consider skipping restart (and republish) for screencast tracks that are no longer live, and guarding the restart/publish loop against exceptions.
Prompt for agents
Was this helpful? React with 👍 or 👎 to provide feedback.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, a stopped MediaProjection cannot be reused. Fixed: republishTrack skips a stopped screencast since the share has ended, restartTrackIfStopped no longer touches screencasts, and the republish loop catches per-track failures so one entry cannot abort the rest.