Skip to content

console: fix WebSocket race and route-remount data flicker#36624

Merged
leedqin merged 1 commit into
MaterializeInc:mainfrom
leedqin:fix-websocket-race-condition
May 19, 2026
Merged

console: fix WebSocket race and route-remount data flicker#36624
leedqin merged 1 commit into
MaterializeInc:mainfrom
leedqin:fix-websocket-race-condition

Conversation

@leedqin
Copy link
Copy Markdown
Contributor

@leedqin leedqin commented May 19, 2026

This fixes CNS-77 where the data explorer spinner keeps spinning for a while. Reported by @sjwiesman and @frankmcsherry , I have only been able to repro this in Safari. Iterated in this draft fix PR: #36613 , there is a race condition in the websocket hook useEffects that initiates the Websocket connection and the second effect kills the CONNECTING socket. I refactored to route the useAutomaticallyConnectWebsocket reconnect signals in the Websocket Connection Manager and added a guard to serialize the overlapping triggers.

Fixed another bug that happens when a user navigates away from Data Explorer page and comes back, it reloads the page. Coming back to Data Explorer, opens a new Websocket connection and reset the state that clobbered the existing snapshot. Fixed the hook useGlobalUpsertSubscribe to hold the cached snapshot until new manager has the data.

Verification

  • Added a test for the race condition
    Before:
data_explorer_spinning.mov
  • Videos of the fix here
exploer_spin_flicker_fix.mov

The hook and the connection manager both initiated WebSocket connects
on first mount; on Safari, closing the still-CONNECTING socket from
the second call sometimes stranded the next one in CONNECTING (CNS-77).
Route the hook's reconnect signals through the manager and add a
connectInFlight guard so overlapping triggers serialize.

Separately, navigating away and back to Data Explorer would clobber
the cached atom with the fresh SubscribeManager's empty pre-snapshot
state, causing the spinner to flash. Hold the cached snapshot in
useGlobalUpsertSubscribe until the new manager has data.
@leedqin leedqin requested a review from a team as a code owner May 19, 2026 17:43
@leedqin leedqin added the A-CONSOLE Area: Console label May 19, 2026
@leedqin leedqin requested review from Alphadelta14 and removed request for a team May 19, 2026 17:43
@leedqin leedqin merged commit 5eaabcb into MaterializeInc:main May 19, 2026
110 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CONSOLE Area: Console

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants