Skip to content

fix: avoid race condition in retro controller analysis loading#2756

Open
lacostej wants to merge 1 commit intolichess-org:mainfrom
lacostej:fix/retro-stuck-loading
Open

fix: avoid race condition in retro controller analysis loading#2756
lacostej wants to merge 1 commit intolichess-org:mainfrom
lacostej:fix/retro-stuck-loading

Conversation

@lacostej
Copy link
Copy Markdown
Contributor

Summary

Fixes #2750

"Learn from your mistakes" can get stuck loading due to a race condition in RetroController.build():

  1. The lastAnalysisEvent listener was registered after requestAnalysis() returned
  2. If analysis completed quickly (e.g. already requested from the analysis screen), the completion event was missed
  3. The controller would wait until the 1-minute timeout before showing an error

The fix:

  • Register the listener before calling requestAnalysis() so no events are missed
  • After the request, check if the analysis already completed (via the ValueNotifier's current value) and process it immediately

Test plan

  • Open a finished game's analysis screen
  • Request server analysis (if not already available)
  • Tap "Learn from your mistakes" — should load without getting stuck
  • Repeat several times rapidly switching between analysis and retro screens

Register the lastAnalysisEvent listener before calling requestAnalysis
to prevent missing events that arrive between the request and listener
registration. Also check if analysis already completed before waiting.

Fixes lichess-org#2750
@lacostej
Copy link
Copy Markdown
Contributor Author

Note: I have to test it a bit more.

@lacostej lacostej marked this pull request as draft March 13, 2026 11:30
@lacostej lacostej marked this pull request as ready for review March 13, 2026 16:43
lacostej added a commit to lacostej/mobile that referenced this pull request Mar 14, 2026
Move connectedStream and stream listener registration before
`await _socketClient.firstConnection` in broadcast and TV controllers
to avoid missing reconnection events during the initial connection.

Similar pattern to the race condition fixed in RetroController (lichess-org#2756).
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.

"Learn from your mistakes" sometimes remains stuck loading

1 participant