Skip to content

fix: Fix handleOpen websocket warnings#19

Merged
lekkas merged 6 commits into
nevuamarkets:mainfrom
felipecsl:main
Dec 9, 2025
Merged

fix: Fix handleOpen websocket warnings#19
lekkas merged 6 commits into
nevuamarkets:mainfrom
felipecsl:main

Conversation

@felipecsl

Copy link
Copy Markdown
Contributor

This fixes warnings like the one below:

2025-12-05T01:39:25.062Z warn: handleOpen called for stale WebSocket instance (groupId: "2719a082-dd80-4284-81e8-9b5b3f52ad0f")
  • Issue: Reconnect loop could spawn a second websocket while the first was still handshaking. When the first finally emitted open, it was no longer current, triggering noisy warnings (“handleOpen called for stale WebSocket instance”) and risking duplicate sockets.
  • Root cause: GroupRegistry.getGroupsToReconnectAndCleanup treated every PENDING group as reconnectable without tracking “connecting” state; GroupSocket.connect also didn’t guard against concurrent calls.
  • Fix: Introduce a connecting flag on WebSocketGroup; GroupSocket.connect early-returns if already connecting and clears the flag in finally; GroupRegistry clears the flag on disconnect and skips reconnecting pending groups that are handshaking or already CONNECTING/OPEN.
  • Suggested tests: Run the sample subscription manager with a large asset list; verify no “stale WebSocket” warnings during startup/reconnect; confirm connections remain stable after forced closes to ensure reconnection still occurs once the flag resets.

@lekkas

lekkas commented Dec 6, 2025

Copy link
Copy Markdown
Contributor

@felipecsl this is incredible, thank you for working on this!

It's been an annoying bug for so long that I genuinely forgot to open an issue for it.

I will run a few manual tests and then merge and publish ASAP

@felipecsl

Copy link
Copy Markdown
Contributor Author

I can’t take credit for it, codex did most of the heavy lifting :)
But happy to help, great library

@lekkas

lekkas commented Dec 9, 2025

Copy link
Copy Markdown
Contributor

Manually tested with ~8K assets, merging and publishing.

Thanks again @felipecsl !

@lekkas lekkas merged commit 4500f9e into nevuamarkets:main Dec 9, 2025
2 checks 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.

2 participants