Skip to content

fix(javascript): flush queued events after WebSocket reconnect#178

Merged
Dobrunia merged 2 commits intomasterfrom
fix/javascript-ws-reconnect-flush-queue
Apr 1, 2026
Merged

fix(javascript): flush queued events after WebSocket reconnect#178
Dobrunia merged 2 commits intomasterfrom
fix/javascript-ws-reconnect-flush-queue

Conversation

@Dobrunia
Copy link
Copy Markdown
Member

Problem

When the collector WebSocket dropped, the SDK queued outgoing events but only ran sendQueue() after the initial connection in the constructor. After a successful reconnect() (or init() when ws === null), the buffer was never drained, so the first hawk.send() after a disconnect could be lost until a later send.

Solution

  • After a successful reconnect(), call sendQueue().
  • When ws === null, after await init() call sendQueue().

Tests

  • Unit tests for CLOSED → reconnect → queued payload sent.
  • Unit test for pagehidews === nullsend() flushes queue.
  • Mock WebSocket must expose numeric CONNECTING / OPEN / CLOSING / CLOSED so switch (readyState) matches real browser behavior.

@Dobrunia Dobrunia requested a review from FeironoX5 March 31, 2026 17:14
@neSpecc neSpecc requested review from Copilot and removed request for FeironoX5 March 31, 2026 17:29
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 eventsQueue after await init() when ws === null in send().
  • Flush eventsQueue after a successful reconnect().
  • Add regression tests covering CLOSED → reconnect → queued payload sent, and pagehidews === nullsend() 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.

@Dobrunia Dobrunia merged commit 295d07f into master Apr 1, 2026
3 checks passed
@Dobrunia Dobrunia deleted the fix/javascript-ws-reconnect-flush-queue branch April 1, 2026 10:13
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.

5 participants