stream: fix uncatchable error closing a half-open Duplex.toWeb()#64161
Open
3zrv wants to merge 1 commit into
Open
stream: fix uncatchable error closing a half-open Duplex.toWeb()#641613zrv wants to merge 1 commit into
3zrv wants to merge 1 commit into
Conversation
…able Signed-off-by: Mohamed Sayed <k@3zrv.com>
Member
|
Can you add the DCO signoff? |
Contributor
Author
|
I think my commit already has it
Unless there's something I missed |
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: #64120
What: Fix an uncatchable
TypeError: Cannot read properties of undefined (reading 'error')thrown frominternal/webstreams/adapterswhen closing the writable side of a half-openDuplex.toWeb()(e.g. a net socket whose peer sent FIN).Why: The writable adapter's
close()has an else-branch (taken whenwritableEndedis already true) that setscontroller = undefinedbut does not detach the eos listener. When the underlying writable's finish/close fires afterward, the eos callback runs controller.error(newAbortError()) on the now-undefined controller and throws. Because the throw happens synchronously inside the finish event emit (not in the close() promise chain), user try/catch around writer.close() cannot catch it and the process crashes.This was latent until v26.3.0. Commit
cbee0de(alignReadable.toWebtermination with eos) made the readable side's eos use writable: false, so reader.read() now resolves on the readable END before the writable FINISH. With allowHalfOpen: false, that landswriter.close()in the exact window wherewritableEnded === truebutwritableFinished === false, triggering the null-deref.How: Guard both
controller.error(...)calls in the eos callback with optional chaining(controller?.error(...)), completing the intent that the controller is inert once close() clears it. The eos listener is intentionally kept attached so its error-handling safety net still swallows any post-close error rather than letting that become uncaught. Adds a deterministic, network-free regression test (aDuplexwithallowHalfOpen: falseand afinal()that defers finish to a macrotask).