fix(node/http): stop leaking TCP wrappers on HTTPS upgrade with createConnection TLSSocket#32961
Merged
bartlomieju merged 4 commits intomainfrom Mar 24, 2026
Merged
fix(node/http): stop leaking TCP wrappers on HTTPS upgrade with createConnection TLSSocket#32961bartlomieju merged 4 commits intomainfrom
bartlomieju merged 4 commits intomainfrom
Conversation
The upgrade callback's socket parameter is typed as Duplex, not Socket. Also flatten the nested promise to avoid a dangling unresolved promise on test cleanup. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The kReinitializeHandle path should only be used when the socket was provided via createConnection as an encrypted TLS socket. For plain HTTP upgrades, create a fresh Socket to avoid dangling state that prevents the close event from firing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
bartlomieju
approved these changes
Mar 24, 2026
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.
Fixes a Node-compat HTTP/TLS bug where
https.request()could leak nativeTCPwrappers whencreateConnectionreturns a pre-createdTLSSocketand the request upgrades the connection.This is the same pattern used by
npm:ws- create the TLS socket first withtls.connect(), then pass it tohttps.request({ createConnection }).This patch:
TLSSocketduring the upgrade path instead of creating a replacement socketsecureConnectbefore flushing the request on pre-createdTLSSocketsUser-visible improvement
With the attached repro, RSS no longer grows linearly with each upgraded connection.
Before this patch:
After this patch:
Script used can be found at https://github.com/magurotuna/tls_then_upgrade/blob/main/client.ts