-
Notifications
You must be signed in to change notification settings - Fork 5k
node:net: reset the stream state when connect() reuses a half-closed socket #38980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
edad317
44e6a05
33e982c
5314d9e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2122,8 +2122,6 @@ Socket.prototype.connect = function connect(...args) { | |
| } | ||
| if (this.destroyed) { | ||
| this._handle = null; | ||
| this._peername = null; | ||
| this._sockname = null; | ||
| } | ||
|
|
||
| this.connecting = true; | ||
|
|
@@ -2134,8 +2132,10 @@ Socket.prototype.connect = function connect(...args) { | |
|
|
||
| if (!this._handle) { | ||
| this._handle = newDetachedSocket(typeof this[bunTlsSymbol] === "function"); | ||
| initSocketHandle(this); | ||
| } | ||
| // Also for a reused handle: doConnect replaces the connection it still | ||
| // carries, so the stream state of that connection has to go with it. | ||
| initSocketHandle(this); | ||
|
claude[bot] marked this conversation as resolved.
Comment on lines
+2136
to
+2137
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 The hostname variant of this fix has a race window: Extended reasoning...What the gap is
The code path that re-corrupts the reset stateDuring that DNS window the old (still-attached) connection can deliver its FIN or close to
The Why the existing tests don't cover itEvery new test in this PR — the rewritten "should allow reconnecting after end()" and all four "connect() while the previous connection is half-closed" cases — connects to Step-by-step trace
Why this is a nit, not a blocker
Per REVIEW.md's "Cover the variant matrix, not just the repro" this is worth noting — the hostname variant is an untested gap — but not worth blocking a PR that fixes the flaky test it set out to fix and strictly improves every case. |
||
|
|
||
| if (!pipe) { | ||
| lookupAndConnect(this, options); | ||
|
|
@@ -4261,10 +4261,11 @@ function normalizeArgs(args: unknown[]): [options: Record<PropertyKey, any>, cb: | |
| return arr; | ||
| } | ||
|
|
||
| // Called when creating new Socket, or when re-using a closed Socket | ||
| // Called on every connect(): a new Socket, or one re-used for another connection. | ||
| function initSocketHandle(self) { | ||
| self._undestroy(); | ||
| self._sockname = null; | ||
| self._peername = null; | ||
| self[kclosed] = false; | ||
| self[kended] = false; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you need a paragraph-long comment to justify why the workaround is OK, the code is wrong — fix the code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trimmed to one line in 5314d9e.