fix(api-client): force WebSocket reconnect after sleep when socket stays OPEN [WPB-21916]#21416
Open
thisisamir98 wants to merge 2 commits into
Open
fix(api-client): force WebSocket reconnect after sleep when socket stays OPEN [WPB-21916]#21416thisisamir98 wants to merge 2 commits into
thisisamir98 wants to merge 2 commits into
Conversation
…ays OPEN After laptop sleep, the TCP connection can die while the browser still reports readyState as OPEN. The sleep handler detected wake correctly, but reconnect was gated on isDisconnected (socket === CLOSED), so the common zombie-OPEN case was skipped and the client could stay silent with no messages and no offline banner. Always call reconnect on wake, regardless of socket state. Add Datadog-friendly logs for wake detection, reconnect initiation, and successful reopen (including idle time and unansweredPing context). Add regression tests to prevent reintroducing the isDisconnected gate.
Contributor
|
🔗 Download Full Report Artifact 🧪 Playwright Test Summary
specs/CriticalFlow/groupCalls-TC-8632.spec.ts (❌ 0 failed,
|
e-maad
reviewed
Jun 2, 2026
| reconnect, | ||
| } as never; | ||
|
|
||
| expect(sleepWakeCallback).toBeDefined(); |
Contributor
There was a problem hiding this comment.
I don't understand why we have to assert if the sleepWakeCallback is defined.
| const mockedOnBackFromSleep = jest.mocked(onBackFromSleep); | ||
|
|
||
| describe('ReconnectingWebsocket back from sleep', () => { | ||
| let sleepWakeCallback: (() => void) | undefined; |
Contributor
There was a problem hiding this comment.
Instead of undefined if we pass an empty function we don't have to use Non-Null Assertion !
| } | ||
|
|
||
| const state = this.getState(); | ||
| const timeSinceLastMessage = this.lastMessageTimestamp > 0 ? Date.now() - this.lastMessageTimestamp : undefined; |
The ping loop previously stopped on close, ping timeout, and each connect(), leaving gaps where a zombie OPEN socket could stay undetected until the next manual recovery path. Start pinging once on first connect and keep the interval running until explicit disconnect. Reschedule the timer after wake-from-sleep so ticks resume promptly when OS timers were suspended. Ping ticks now force reconnect on CLOSED sockets and unanswered pong timeouts without stopping the interval, and reset ping state on open/close. Add tests for persistent pinging across close and ping timeout, CLOSED reconnect on ping tick, and sleep wake rescheduling.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



After laptop sleep, the TCP connection can die while the browser still reports readyState as OPEN. The sleep handler detected wake correctly, but reconnect was gated on isDisconnected (socket === CLOSED), so the common zombie-OPEN case was skipped and the client could stay silent with no messages and no offline banner.
Always call reconnect on wake, regardless of socket state. Add Datadog-friendly logs for wake detection, reconnect initiation, and successful reopen (including idle time and unansweredPing context). Add regression tests to prevent reintroducing the isDisconnected gate.