Skip to content

47593 frontend [ websocket ] Catch errors for websockets#240

Merged
pneumatic-ilyacedrik merged 2 commits into
masterfrom
frontend/websocket/47593__Catch_errors_for_websockets
Jun 19, 2026
Merged

47593 frontend [ websocket ] Catch errors for websockets#240
pneumatic-ilyacedrik merged 2 commits into
masterfrom
frontend/websocket/47593__Catch_errors_for_websockets

Conversation

@pneumatic-ilyacedrik

@pneumatic-ilyacedrik pneumatic-ilyacedrik commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Note

Medium Risk
Changes affect realtime updates (tasks, notifications, users) and logout/session transitions; mis-timed cancel/close could briefly drop or duplicate connections, but scope is frontend-only with defensive error handling.

Overview
Hardens realtime WebSocket handling so bad messages and routing failures are logged instead of breaking the listener, and moves connection start/stop out of MainLayout into the auth saga.

Error handling: createWebSocketChannel wraps JSON parsing in try/catch, adds onerror logging, and sets shouldRemove on channel teardown so cleanup does not auto-reconnect. watchWsEvents catches errors from routeRealtimeEvent per envelope. Unhandled-event logs in routeRealtimeEvent are slightly simplified.

Lifecycle: MainLayout no longer checks hasActiveConnections, closes sockets, or delays before watchUserWSEventsAction—it dispatches watch when billingPlan is set. The auth saga tracks the forked watchWsEvents task, cancels it and calls closeAllConnections via stopWatchWsEvents (including on logout), restarts before a new fork, and uses takeLeading on WatchUserWSEvents to avoid overlapping watchers.

Reviewed by Cursor Bugbot for commit d971733. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Catch and handle WebSocket errors and prevent duplicate watcher tasks

  • Wraps the event routing loop in watchWsEvents.ts in a try/catch so routing errors are logged rather than crashing the watcher.
  • Invalid WebSocket messages and connection errors in createWebSocketChannel.ts are now caught and logged instead of potentially breaking the channel.
  • Introduces stopWatchWsEvents in auth saga to cancel the active watcher task and close all connections; called on logout and before starting a new watcher.
  • Switches watchUserWSEvents from takeEvery to takeLeading so concurrent watcher tasks cannot overlap.
  • Unsubscribing from a WebSocket channel now sets ws.shouldRemove = true to prevent the onclose handler from triggering a reconnect.

Macroscope summarized d971733.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit d971733. Configure here.

Comment thread frontend/src/public/redux/auth/saga.ts
@pneumatic-ilyacedrik pneumatic-ilyacedrik merged commit 22b787b into master Jun 19, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Frontend Web client changes request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants