Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ext/node/polyfills/internal/webstreams/adapters.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,8 @@ export function newReadableStreamFromStreamReadable(

streamReadable.pause();

let isCanceled = false;

const cleanup = finished(streamReadable, (error) => {
if (error?.code === "ERR_STREAM_PREMATURE_CLOSE") {
const err = new AbortError(undefined, { cause: error });
Expand All @@ -529,6 +531,9 @@ export function newReadableStreamFromStreamReadable(
if (error) {
return controller.error(error);
}
if (isCanceled) {
return;
}
controller.close();
});

Expand All @@ -544,7 +549,8 @@ export function newReadableStreamFromStreamReadable(
},

cancel(reason) {
destroy(streamReadable, reason);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that Node.js, keeps track of wasCanceled variable here and then later uses it to decide if the controller should be closed. Have you tried this approach? https://github.com/nodejs/node/blob/886e4b3b534a9f3ad2facbc99097419e06615900/lib/internal/webstreams/adapters.js#L499

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed!

isCanceled = true;
destroy.call(streamReadable, reason);
},
}, strategy);
}
Expand Down
1 change: 1 addition & 0 deletions tests/node_compat/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,7 @@
"parallel/test-stream-readable-setEncoding-existing-buffers.js" = {}
"parallel/test-stream-readable-setEncoding-null.js" = {}
"parallel/test-stream-readable-strategy-option.js" = {}
"parallel/test-stream-readable-to-web-termination.js" = {}
"parallel/test-stream-readable-unpipe-resume.js" = { flaky = true }
"parallel/test-stream-readable-unshift.js" = {}
"parallel/test-stream-readable-with-unimplemented-_read.js" = {}
Expand Down
Loading