Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webstream: convert premature close to AbortError #39524

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
15 changes: 14 additions & 1 deletion lib/internal/webstreams/adapters.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const {
ERR_INVALID_STATE,
ERR_STREAM_PREMATURE_CLOSE,
},
AbortError,
} = require('internal/errors');

const {
Expand Down Expand Up @@ -120,6 +121,12 @@ function newWritableStreamFromStreamWritable(streamWritable) {
}

const cleanup = finished(streamWritable, (error) => {
if (error?.code === 'ERR_STREAM_PREMATURE_CLOSE') {
const err = new AbortError();
err.cause = error;
error = err;
}

cleanup();
// This is a protection against non-standard, legacy streams
// that happen to emit an error event again after finished is called.
Expand All @@ -144,7 +151,7 @@ function newWritableStreamFromStreamWritable(streamWritable) {
closed = undefined;
return;
}
controller.error(new ERR_STREAM_PREMATURE_CLOSE());
controller.error(new AbortError());
controller = undefined;
});

Expand Down Expand Up @@ -395,6 +402,12 @@ function newReadableStreamFromStreamReadable(streamReadable) {
streamReadable.pause();

const cleanup = finished(streamReadable, (error) => {
if (error?.code === 'ERR_STREAM_PREMATURE_CLOSE') {
const err = new AbortError();
err.cause = error;
error = err;
}

cleanup();
// This is a protection against non-standard, legacy streams
// that happen to emit an error event again after finished is called.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const {
const reader = readableStream.getReader();

assert.rejects(reader.closed, {
code: 'ERR_STREAM_PREMATURE_CLOSE',
code: 'ABORT_ERR',
});

readable.on('end', common.mustNotCall());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ const {
const writer = writable.getWriter();

assert.rejects(reader.closed, {
code: 'ERR_STREAM_PREMATURE_CLOSE',
code: 'ABORT_ERR',
});

assert.rejects(writer.closed, {
code: 'ERR_STREAM_PREMATURE_CLOSE',
code: 'ABORT_ERR',
});

duplex.destroy();
Expand Down Expand Up @@ -165,7 +165,7 @@ const {

reader.closed.then(common.mustCall());
assert.rejects(writer.closed, {
code: 'ERR_STREAM_PREMATURE_CLOSE',
code: 'ABORT_ERR',
});

duplex.end();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class TestWritable extends Writable {
const writableStream = newWritableStreamFromStreamWritable(writable);

assert.rejects(writableStream.close(), {
code: 'ERR_STREAM_PREMATURE_CLOSE'
code: 'ABORT_ERR'
});

writable.end();
Expand Down