fix: resolve post-reconnection state desync#51
Merged
Conversation
8b84f0f to
41f524e
Compare
… stopped) Four related fixes for state synchronization after network reconnection (e.g., cell to WiFi transition): 1. Add DRAINING check to onStateChanged - previously only onGroupUpdate had this protection. A server/state "stopped" message during DRAINING now sends play() to resume instead of clearing the buffer. 2. Defer exitDraining() until after the first state/group message is processed. Previously, onReconnected posted exitDraining() to the mainHandler before onStateChanged/onGroupUpdate, so the DRAINING checks would see PLAYING instead of DRAINING. 3. Sync playWhenReady in updateStateFromPlayer() when audio is physically PLAYING/DRAINING. If playWhenReady was stale (false from an earlier server "stopped"), the UI would show "not playing" even though audio was audible. 4. Move updatePlayWhenReadyFromServer() into per-state branches in both handlers. During DRAINING+STOPPED, playWhenReady is not set to false, preventing the UI from briefly flipping to "stopped" before the server resumes playback.
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.
Summary
Fixes a bug where audio continues playing but the UI shows "stopped" after a network reconnection (e.g., switching from cellular to WiFi).
Root cause: After reconnection, the server pushes a "stopped" state (because the player briefly disconnected). The client's
onStateChangedhandler had no DRAINING protection, so it would unconditionally setplayWhenReady=falseand clear the buffer -- even while audio was still playing from the reconnection buffer. A timing race withexitDraining()meant the DRAINING check inonGroupUpdatealso couldn't fire in time.Four fixes:
onStateChanged(previously onlyonGroupUpdatehad it)exitDraining()until after the first state/group message is processed (fixes mainHandler ordering race)playWhenReadyinupdateStateFromPlayer()when audio is physically PLAYING/DRAINING (safety net)updatePlayWhenReadyFromServer()into per-state branches so it's skipped during DRAINING+STOPPEDTest plan
ReconnectStateSyncTestwith 13 tests covering all 4 fixes