Repository navigation
fix(client): prevent late connections after shutdown - #3499
Conversation
|
Thanks, we will take a look |
|
Thanks for the careful work and the tests. We've decided not to take this. The full fix needs extra connection-state tracking in the socket, and we don't think it's worth that for this case. It only happens if you destroy or close a client before |
nkaradzhov
left a comment
There was a problem hiding this comment.
@jakobzach could you add one socket-level regression test for the reconnect path? The test should destroy after reconnecting, then let the replacement socket connect, and assert that it is destroyed and that no connect/ready events fire. The current tests cover only the first connect.\n\nAfter that, I'll review it promptly. Thanks again for the careful report.
|
Added the requested reconnect regression in abf5b62. It awaits initial readiness, destroys after automatic reconnect starts, then verifies the late socket is destroyed with no 24 focused tests, build, client type tests and lint pass. The PR description also explains why the existing pre-ready |
…ining Guard the pending socket on a teardown counter bumped by destroySocket() instead of on #isOpen. destroy() and close() with an empty queue still drop the late socket, but close() with queued commands lets it connect and drain, as before. This removes the need to turn close() before ready into destroy().
|
Hey @jakobzach, thanks! I pushed a small tweak on top. I should have asked for it earlier, but I didn't, so I fixed it myself instead of sending you on another round. TLDR: the late-socket guard now fires only after a real teardown, so |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9bd8a572cb
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| try { | ||
| const connectStartTime = performance.now(); | ||
| const socket = this.#socket = await this.#createSocket(); | ||
| const teardownEpoch = this.#teardownEpoch; |
There was a problem hiding this comment.
Carry teardown state across the reconnecting callback
When close() with an empty queue or destroy() is called synchronously from a client's reconnecting listener after a ready connection fails, #onSocketError invokes #connect(1) only after that listener returns. This line therefore records the already-incremented epoch, the comparison below succeeds, and the replacement can emit connect/ready for the closed client; preserve the epoch from before emitting reconnecting or suppress the post-listener attempt when teardown ran.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
@nkaradzhov should I open a follow-up PR for this? I’d suggest checking whether the callback shut the client down before starting another connection.
Description
Fixes #3498.
Destroying a client during automatic reconnect can miss the pending replacement TCP socket, which later connects and revives the closed client. Reject and destroy that late socket before assigning it or emitting
connect/ready, using the existingisOpenflag.The socket regression first awaits a successful connection, triggers automatic reconnect, destroys after
reconnectingwhile the replacement TCP socket is pending, then verifies that the late socket is destroyed without events or a second initiator call.The four-line public
close()cleanup is required alongside the guard: without it, closing before ready with queued commands rejectsconnect()but leaves the commands andclose()pending. Focused public-client tests cover that settlement and preserve graceful draining after readiness. README documents the distinction.Validation
f6e267fcacd735992bcf8c2b3be17f48eed6e00band passes with the guard.socketTimeouttests and the existing retry-counter failure.connections[0]is undefined). Docker-backed tests were not rerun in this follow-up.Run the requested regression with:
npm run test-single -- packages/client/lib/client/socket.spec.ts --grep 'replacement TCP connection is pending'Checklist
npm testpass with this change (including linting)?