Skip to content

Fix websocket reconnect state timing#1391

Open
0xgeorgemathew wants to merge 1 commit intopingdotgg:mainfrom
0xgeorgemathew:ws-reconnect-state
Open

Fix websocket reconnect state timing#1391
0xgeorgemathew wants to merge 1 commit intopingdotgg:mainfrom
0xgeorgemathew:ws-reconnect-state

Conversation

@0xgeorgemathew
Copy link

@0xgeorgemathew 0xgeorgemathew commented Mar 24, 2026

What Changed

Updated the web socket transport to report reconnecting as soon as a reconnect attempt is scheduled, instead of waiting until the next socket attempt starts.

Added a regression test covering the backoff window after a socket close.

Why

After a socket close, the transport scheduled a reconnect timer but kept reporting closed until the timer fired. That made the transport state inaccurate during reconnect backoff.

This keeps the state machine aligned with the actual retry lifecycle without changing transport behavior beyond the reported state.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Note

Low Risk
Low risk: changes only the reported WsTransport state during reconnect backoff and adds a regression test; no protocol, request handling, or retry timing behavior changes.

Overview
Updates WsTransport to switch to reconnecting immediately when a reconnect timer is scheduled (instead of remaining closed until the next connect() call).

Adds a Vitest regression test using fake timers to assert the transport reports reconnecting right after a socket close and before the next WebSocket attempt is created.

Written by Cursor Bugbot for commit 63c72b9. This will update automatically on new commits. Configure here.

Note

Fix WsTransport to report 'reconnecting' state immediately when reconnect is scheduled

Previously, WsTransport.getState() would not return 'reconnecting' until a later phase of the reconnect flow. Now this.state is set to 'reconnecting' at the start of scheduleReconnect(), before the delay is calculated and the timeout is set. A new test in wsTransport.test.ts uses fake timers to assert the state is correct immediately after socket close.

Macroscope summarized 63c72b9.

@coderabbitai
Copy link

coderabbitai bot commented Mar 24, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 2cfe870a-58c0-453c-b310-3c22e612443a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant