Repository navigation
fix(node_stream): handle Web Stream adapter errors - #36193
Conversation
bartlomieju
left a comment
There was a problem hiding this comment.
LGTM. The core fix is correct and complete: Deno's destroy (internal/streams/destroy.js) is a prototype method that reads this._readableState/this._writableState, so the old plain destroy(duplex, error) calls set this=undefined and passed the stream as the error arg. Converting every site to destroy.call(stream, error) is the right fix, and I confirmed all the buggy call sites are covered. The writev normalization correctly forwards a single Error to the Node callback (Promise.all only rejects with the first scalar error, so nothing is dropped), and I traced every settle path for the added .catch(done): it cannot double-invoke the callback since done is throw-safe, so there is no ERR_MULTIPLE_CALLBACK risk.
A few optional, non-blocking nits:
tests/node_compat/config.jsonc: the new entry breaks the alphabetical ordering (duplexsorts aftercompose); it belongs aftertest-webstreams-decompression-reject-trailing.js.adapters.js: the.catch(done)is near-dead and diverges from upstream. Every settle path already routes throughdone, so it only fires on a synchronous throw inside the fulfillment arrow, whichwriter.writedoes not normally do. A one-line comment naming the case it guards, or dropping it, would be clearer.- The 6-line writev error-normalization block is duplicated verbatim across the Writable and Duplex adapters. Upstream keeps the two
done()functions separate so the duplication is defensible, but a small file-local helper would read nicer.
Nice test coverage.
…g, document .catch(done)
## Summary - bind the internal destroy helper to the adapted Node stream - normalize scalar, array, and missing writev completion values - add focused adapter coverage and enable the corresponding upstream Node regression ## Details Several Web Stream adapter failure paths called an instance-oriented destroy helper as a plain function. The batch write completion path also assumed every value was an array, although promise rejection handlers receive a scalar error. These paths could replace the original stream failure with a secondary exception or unhandled rejection. Bind each destroy call to the appropriate stream, pass the first write error through the Node callback, and route terminal promise-chain failures through the same completion path. ## Validation - ./tools/format.js - cargo build - cargo test -p unit_node_tests --test unit_node stream_test -- --nocapture - cargo test -p node_compat_tests --test node_compat test-webstreams-duplex-fromweb-writev-unhandled-rejection -- --nocapture
Summary
Details
Several Web Stream adapter failure paths called an instance-oriented destroy helper as a plain function. The batch write completion path also assumed every value was an array, although promise rejection handlers receive a scalar error. These paths could replace the original stream failure with a secondary exception or unhandled rejection.
Bind each destroy call to the appropriate stream, pass the first write error through the Node callback, and route terminal promise-chain failures through the same completion path.
Validation