Repository navigation
node:net: Don't start reading a paused socket when it closes - #8502
Merged
Merged
Conversation
When a socket's connection closes while nobody is reading it, because it is paused or stopped on backpressure, onConnectionClosed() ends the readable and calls read(0) so that 'end' fires, as in Node. That read(0) went through the socket's read() override, which starts the read loop whenever kBuffer is set, and workerd always sets it. So a paused socket started reading as soon as its connection closed. startRead() already calls the Readable's own read(0) at EOF for this reason. onConnectionClosed() now does the same. A read of a tunnel the service failed currently ends in EOF, so the stray read went unnoticed. Once capnproto's CONNECT adapter fails such reads with the service's error, a paused socket whose peer resets the connection is destroyed with "read ECONNRESET" from that read, rather than with "write ECONNRESET" from the write that observes the reset, as in Node. testNetConnectionResetWrite@all-autogates fails that way against that capnproto change, and passes with this one.
There was a problem hiding this comment.
✅ Approved — The one-file change is small and consistent with the existing startRead() EOF handling, and no issues were found.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
📋 Code reviewer: ✅ LGTM
No issues found.
Reviewed commit: af0211e4
jasnell
approved these changes
Nov 17, 2026
6 tasks done
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.
When a socket's connection closes while nobody is reading it, because it is paused or stopped on backpressure, onConnectionClosed() ends the readable and calls read(0) so that 'end' fires, as in Node. That read(0) went through the socket's read() override, which starts the read loop whenever kBuffer is set, and workerd always sets it. So a paused socket started reading as soon as its connection closed.
startRead() already calls the Readable's own read(0) at EOF for this reason. onConnectionClosed() now does the same.
A read of a tunnel the service failed currently ends in EOF, so the stray read went unnoticed. Once capnproto's CONNECT adapter fails such reads with the service's error, a paused socket whose peer resets the connection is destroyed with "read ECONNRESET" from that read, rather than with "write ECONNRESET" from the write that observes the reset, as in Node. testNetConnectionResetWrite@all-autogates fails that way against that capnproto change, and passes with this one.
How did I get here
What the test does: it connects to a sidecar server that resets the connection, with allowHalfOpen: true. It calls socket.pause() before the connection opens, so nothing should ever read. Then it writes 'x' every 10 ms until an 'error' arrives, and expects that error to be Error: write ECONNRESET with syscall === 'write'.
How it breaks with the capnproto capnproto/capnproto#2931 change: