Drop a node:net socket's handle when it is destroyed #8665
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 296 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.341
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #8665"
general
weight: 0.35
littledivy
Node sets
_handleto null inSocket#_destroy, sobufferSizereadsundefinedonce a socket is destroyed or closed, andpendingreadstrueagain. workerd kept the handle after close. As a resultbufferSizestayed0, and the tls port of test-tls-streamwrap-buffersize pinned that with a TODO:bytesWrittenwas also short while connecting. The first write waits in_pendingDataand later ones queue inwritableBuffer, but only the pending one was counted, so three one-byte writes before'connect'reported 1 where Node reports 3.In this patch:
_destroysaves the byte counters and drops the handle before closing it, as Node does.bytesReadandbytesWrittenread the saved totals as before.net.Serverno longer starts reading a connection that its'connection'listener destroyed. Before, that threw and left the server unable to close.'close'listener no longer closes the handle a second time. It resets the session state and setssslto null, as Node's_destroySSLdoes.JSStreamSocket#doCloseno longer asserts that the handle is still set, since it may now be gone.bytesWrittennow also adds the queued writes, as Node's getter does.Both are Node parity fixes, so they ship without a compatibility flag.
Tests:
undefined.bufferSizeTracksQueuein the net streams suite readsbufferSizeinside the'finish'listener, because the peer has already ended and the socket auto-destroys right after it. It then expectsundefinedonce closed.'connection'and waits for the server's'close'. It times out without the fix.tls.connect({ socket })first, then checkssslis null and that no global'error'fires.bufferSize,writableLength,bytesWrittenandpendingagainst values taken from Node v26, while connecting, on'finish', on'close', and right afterdestroy(). It fails without the fix. At'connect'the queued writes are still in flight in workerd, where Node has already flushed them, so that point only checks thatbufferSizeequalswritableLength.