Skip to content

fix: websocket close code, don't kill connecting sockets on online, single keepalive frame - #175

Merged
boehlerlukas merged 1 commit into
masterfrom
fix-websocket-close-code
Oct 11, 2026
Merged

boehlerlukas merged 1 commit into
masterfrom
fix-websocket-close-code

Conversation

@boehlerlukas

Copy link
Copy Markdown
Contributor

Why

Server-side churn data shows browser SDK sockets are under 1% of short-lived websocket connections, so the impact is small. This change still removes the 1005 ("no status") closes the server records for the SDK's own disconnects, and it stops needless reconnects.

Changes (src/GleapStreamedEvent.js)

  • Close code: cleanupWebSocket() now closes with close(1000, 'client closing') instead of a bare close(). Every intentional close goes through it: restart on gleapId change, stop()/destroy, and the reconnect paths. The call is wrapped in try/catch.
  • online handler: it now reconnects only when there is no socket or the socket is CLOSING/CLOSED. Before, it reconnected unless the socket was OPEN, which killed a socket that was still CONNECTING.
  • Keepalive: the SDK now sends a single 'PING' text frame every 25 s. Before, it sent two frames every 10 s: 'PING' plus a stray 0x9, which went out as the text "9".
    • The server (Server/src/api/websocket/server.ts) registers no message listener on client sockets, so it ignores both frames.
    • The ws LB has no idle-timeout override in the repo, so it uses the DigitalOcean default of 60 s, and 25 s keeps the socket alive.
    • The interval callback also null-guards this.socket.
  • readyState checks: these now compare against the spec values 0/1 instead of this.socket.OPEN.
  • restart(): unchanged. It already reconnects only when the gleapId changed, and stop() resets connectedWebSocketGleapId.

No version bump and no release. The build/ and published/ bundles are not touched.

Tests

  • npm test: 31 suites and 524 tests pass, including the existing GleapStreamedEvent reconnect tests (online/offline, SDK closes never reconnect, single pending reconnect).
  • npm run build: compiles, with 3 warnings that were already there.

🤖 Generated with Claude Code

…ingle keepalive frame

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@boehlerlukas
boehlerlukas merged commit 93607d3 into master Oct 11, 2026
1 check passed
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