← Back to Pull requests

Drop a node:net socket's handle when it is destroyed #8665

Closed
unknown closed this pull request without merging on Nov 20, 2026 04:26 UTC
View on GitHub
unknown unknown commented on Nov 19, 2026 10:07 UTC
Author

Node sets _handle to null in Socket#_destroy, so bufferSize reads undefined once a socket is destroyed or closed, and pending reads true again. workerd kept the handle after close. As a result bufferSize stayed 0, and the tls port of test-tls-streamwrap-buffersize pinned that with a TODO:

socket.on('close', () => console.log(socket.bufferSize, socket.pending));
// Node: undefined true
// workerd: 0 false

bytesWritten was also short while connecting. The first write waits in _pendingData and later ones queue in writableBuffer, but only the pending one was counted, so three one-byte writes before 'connect' reported 1 where Node reports 3.

In this patch:

  • _destroy saves the byte counters and drops the handle before closing it, as Node does. bytesRead and bytesWritten read the saved totals as before.

  • net.Server no longer starts reading a connection that its 'connection' listener destroyed. Before, that threw and left the server unable to close.

  • TLSSocket's 'close' listener no longer closes the handle a second time. It resets the session state and sets ssl to null, as Node's _destroySSL does.

  • JSStreamSocket#doClose no longer asserts that the handle is still set, since it may now be gone.

  • bytesWritten now also adds the queued writes, as Node's getter does.
  • Both are Node parity fixes, so they ship without a compatibility flag.

    Tests:

  • The tls buffersize test now expects undefined.

  • bufferSizeTracksQueue in the net streams suite reads bufferSize inside the 'finish' listener, because the peer has already ended and the socket auto-destroys right after it. It then expects undefined once closed.

  • A new net-server case destroys the socket in 'connection' and waits for the server's 'close'. It times out without the fix.

  • A new tls case ends the Duplex under tls.connect({ socket }) first, then checks ssl is null and that no global 'error' fires.

  • A new port of test-net-buffersize checks bufferSize, writableLength, bytesWritten and pending against values taken from Node v26, while connecting, on 'finish', on 'close', and right after destroy(). 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 that bufferSize equals writableLength.
  • Diff: 296 lines (+222 / -74) across 3 files Reviewer: littledivy Review duration: 1099m
    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
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40.0% (MEDIUM) · Higher = larger blast radius
    40.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.8% · Safe to merge
    15.8%