chore: added websocket pkg & client reconnection state - #388
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe WebSocket client now uses per-connection lifecycle guards and a centralized ChangesWebSocket reconnection lifecycle
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant WebSocket
participant reconnect
participant connectToTraceStream
WebSocket->>reconnect: error or close event
reconnect->>reconnect: validate reconnect state
reconnect->>reconnect: calculate exponential delay
reconnect->>connectToTraceStream: invoke after timeout
connectToTraceStream->>WebSocket: establish timed trace-stream connection
Possibly related issues
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@examples/api-clients/websocket-client/index.js`:
- Around line 161-163: Update the reconnect timeout callback around
connectToTraceStream so it does not clear isReconnecting before creating the
replacement socket. Ensure delayed close events from superseded sockets are
ignored and cannot schedule additional retries, while preserving the single
reconnect flow.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 4d90e1d3-e99e-4e87-9cec-af9a79a02cfb
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (2)
examples/api-clients/websocket-client/index.jsexamples/api-clients/websocket-client/package.json
|
The CI Rust Checks isnt from my changes, pls review |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@examples/api-clients/websocket-client/index.js`:
- Around line 44-45: Update the WebSocket construction in reconnect() to pass
the configured handshakeTimeout option to new WebSocket(WS_URL). Preserve the
existing socket assignment and error/close handlers so timed-out connection
attempts trigger the current retry flow.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: ade6508c-9c01-4c2b-9674-ce6dcf199233
📒 Files selected for processing (1)
examples/api-clients/websocket-client/index.js
Summary
Refactored index.js to convert the WebSocket trace client into an autonomous self-healing system capable of surviving transient network blips and server restarts.
Changes Made
WebSocket Client Example
index.js
connectToTraceStream()as the primary connection method.reconnect()method with persistent attempt counting (reconnectAttempts).Math.min(MAX_RECONNECT_DELAY, INITIAL_RECONNECT_DELAY * Math.pow(2, reconnectAttempts - 1)).setTimeoutcall to asynchronously triggerconnectToTraceStream().MAX_RECONNECT_ATTEMPTS = 10threshold before exiting.ws.on('error'): Logs the error and invokesreconnect().ws.on('close'): Checks if client was intentionally stopped (stopped), otherwise invokesreconnect().lastSeenNodeIdoutside connection scope forresume_fromresume cursor upon reconnection.reconnectAttempts = 0on successfulopenevent.Verification Results
Automated & Manual Testing
node --checkpassed cleanly with no errors.Closes #317
Summary by CodeRabbit