fix(javascript): flush queued events after WebSocket reconnect#178
Merged
fix(javascript): flush queued events after WebSocket reconnect#178
Conversation
neSpecc
approved these changes
Mar 31, 2026
There was a problem hiding this comment.
Pull request overview
Fixes a JavaScript SDK reliability issue where events queued during a WebSocket disconnect were not being flushed after a successful reconnect (or after re-initializing when ws === null), causing the first send() after connection loss to be delayed/lost until a later send.
Changes:
- Flush
eventsQueueafterawait init()whenws === nullinsend(). - Flush
eventsQueueafter a successfulreconnect(). - Add regression tests covering CLOSED → reconnect → queued payload sent, and
pagehide→ws === null→send()flushes the queue (including a helper to patch WebSocket readyState constants for mocks).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
packages/javascript/src/modules/socket.ts |
Ensures queued events are drained after reconnect and after re-init from ws === null. |
packages/javascript/tests/socket.test.ts |
Adds regression tests + improves WebSocket mocking realism by patching static readyState constants. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
FeironoX5
approved these changes
Apr 1, 2026
slaveeks
approved these changes
Apr 1, 2026
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.
Problem
When the collector WebSocket dropped, the SDK queued outgoing events but only ran
sendQueue()after the initial connection in the constructor. After a successfulreconnect()(orinit()whenws === null), the buffer was never drained, so the firsthawk.send()after a disconnect could be lost until a later send.Solution
reconnect(), callsendQueue().ws === null, afterawait init()callsendQueue().Tests
pagehide→ws === null→send()flushes queue.WebSocketmust expose numericCONNECTING/OPEN/CLOSING/CLOSEDsoswitch (readyState)matches real browser behavior.