fix: don't reconnect a websocket after close() - #120
Merged
EnriqueL8 merged 5 commits intoSep 14, 2026
Merged
Conversation
Signed-off-by: Anna McAllister <anna.mcallister@kaleido.io>
Signed-off-by: Anna McAllister <anna.mcallister@kaleido.io>
Signed-off-by: Anna McAllister <anna.mcallister@kaleido.io>
Signed-off-by: Anna McAllister <anna.mcallister@kaleido.io>
Signed-off-by: Anna McAllister <anna.mcallister@kaleido.io>
EnriqueL8
approved these changes
Sep 14, 2026
EnriqueL8
left a comment
Contributor
There was a problem hiding this comment.
Thanks @annamcallister looks good
| node-version: '24.x' | ||
| registry-url: 'https://registry.npmjs.org' | ||
| # Ensure npm 11.5.1 or later required by trusted publishing | ||
| - name: Update npm |
Contributor
There was a problem hiding this comment.
I assume the node-version 24 includes 11.5.1?
Contributor
Author
There was a problem hiding this comment.
yes- 24.x should resolve to node 24.21.0/ npm 11.19.0 right now, and obviously only ever go up
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
FireFlyWebSocket.close()isn't terminal. A closed socket can come back two ways:close()never clearedreconnectTimer— onlyconnect()did. Closing during the reconnect backoff leaves the timer running; it later fires and callsconnect().reconnect()had no notion of "already closed" — theunexpected-responsehandler calls it from a deferred streamflush, so a rejection still being drained whenclose()ran schedules a fresh retry afterwards.Either way the socket reconnects after the application has closed it and dropped its reference, so nothing is left that can stop it, and it retries every
reconnectDelayindefinitely.Since
socketOptionsheaders are fixed at construction, if the connection was authenticated with a credential that later expires, every retry fails — an endless stream of rejected connections from a socket the application believes is gone.Fix
A
closingflag:close()sets it, and clearsreconnectTimerreconnect()returns early when setconnect()clears it, so reopening still worksBoth halves of
close()are load-bearing: the flag stops a futurereconnect()call, while theclearTimeoutstops an already-scheduled retry — a pending timer callsconnect()directly and never goes throughreconnect().connect()'s ownreconnectTimerteardown is removed, sinceclose()(called on the line above) now owns it.