Skip to content

fix(infra): implement resilient WebSocket heartbeat and unified connection state#692

Open
rajesh-puripanda wants to merge 1 commit into
viru0909-dev:mainfrom
rajesh-puripanda:fix/websocket-connection-stability
Open

fix(infra): implement resilient WebSocket heartbeat and unified connection state#692
rajesh-puripanda wants to merge 1 commit into
viru0909-dev:mainfrom
rajesh-puripanda:fix/websocket-connection-stability

Conversation

@rajesh-puripanda
Copy link
Copy Markdown

Summary

Closes #465

Fixes the production WebSocket connection failure for 'Nyay Saarthi' (#465). This PR eliminates the UI state collisions and connection drops occurring between the Vercel frontend and Render backend.

Technical Changes

  • Infrastructure (Heartbeat): Added a 30s heartbeat ping interval to prevent Render's 50s idle connection timeout.
  • State Machine: Replaced ambiguous boolean flags with a centralized status enum (disconnected, connecting, connected, reconnecting, failed) to ensure UI consistency.
  • Robustness:
    • Implemented an exponential backoff reconnection strategy (capped at 30s) that dynamically re-fetches auth tokens from localStorage to ensure valid handshake sessions.
    • Added defensive cleanup for onerror events and manual connection triggers to prevent orphaned timers/race conditions.
  • UI/UX:
    • Centralized status management in NotificationBell.jsx via statusListeners.
    • Added a clear status indicator (dot/banner) to provide immediate feedback on connection health.
    • Suppressed "all caught up" empty states during failure to avoid confusing the user.

Testing Performed

  • Verified heartbeat frames maintain persistent connection through idle periods.
  • Tested state machine integrity (no conflicting banners).
  • Validated token refresh during reconnection backoff.
  • Confirmed cleanup of timers on component unmount and explicit disconnects.

Closes #465

@vercel
Copy link
Copy Markdown

vercel Bot commented May 27, 2026

@rajesh-puripanda is attempting to deploy a commit to the CodeBlooded's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

[BUG]: WebSocket connection fails on production , Nyay Saarthi permanently broken on live site

1 participant