fix(node/http): stop leaking TCP wrappers on HTTPS upgrade with createConnection TLSSocket (#32961)
Fixes a Node-compat HTTP/TLS bug where `https.request()` could leak
native `TCP` wrappers when `createConnection` returns a pre-created
`TLSSocket` and the request upgrades the connection.
This is the same pattern used by `npm:ws` - create the TLS socket first
with `tls.connect()`, then pass it to `https.request({ createConnection
})`.
This patch:
- reuses the original encrypted `TLSSocket` during the upgrade path
instead of creating a replacement socket
- skips the sock-init workaround for sockets that are already encrypted
- waits for `secureConnect` before flushing the request on pre-created
`TLSSocket`s
- preserves the TLS-upgrade state needed when the handle is
reinitialized
---------
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>