Skip to content

Commit fa05a8e

Browse files
author
Mohamed Sayed
committed
stream: fix uncatchable error closing a half-open Duplex.toWeb() writable
Signed-off-by: Mohamed Sayed <k@3zrv.com>
1 parent 62a3b1b commit fa05a8e

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

lib/internal/webstreams/adapters.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ function newWritableStreamFromStreamWritable(streamWritable, options = kEmptyObj
216216
closed.reject(error);
217217
closed = undefined;
218218
}
219-
controller.error(error);
219+
controller?.error(error);
220220
controller = undefined;
221221
return;
222222
}
@@ -226,7 +226,7 @@ function newWritableStreamFromStreamWritable(streamWritable, options = kEmptyObj
226226
closed = undefined;
227227
return;
228228
}
229-
controller.error(new AbortError());
229+
controller?.error(new AbortError());
230230
controller = undefined;
231231
});
232232

test/parallel/test-whatwg-webstreams-adapters-to-readablewritablepair.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const {
1010
} = require('internal/webstreams/adapters');
1111

1212
const {
13+
Duplex,
1314
PassThrough,
1415
} = require('stream');
1516

@@ -254,3 +255,27 @@ const {
254255
code: 'ERR_INVALID_ARG_TYPE'
255256
});
256257
}
258+
259+
{
260+
const duplex = new Duplex({
261+
allowHalfOpen: false,
262+
read() {},
263+
write(chunk, enc, cb) { cb(); },
264+
final(cb) { setImmediate(cb); },
265+
});
266+
267+
const {
268+
readable,
269+
writable,
270+
} = newReadableWritablePairFromDuplex(duplex);
271+
272+
const reader = readable.getReader();
273+
const writer = writable.getWriter();
274+
275+
duplex.push(null);
276+
277+
reader.read().then(common.mustCall(({ done }) => {
278+
assert.strictEqual(done, true);
279+
writer.close().then(common.mustCall());
280+
}));
281+
}

0 commit comments

Comments
 (0)