Skip to content

Commit fe06bf5

Browse files
3zrvaduh95
authored andcommitted
stream: fix uncatchable error closing half-open Duplex.toWeb() writable
Signed-off-by: Mohamed Sayed <k@3zrv.com> PR-URL: #64161Fixes: #64120 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Jason Zhang <xzha4350@gmail.com> Reviewed-By: Aviv Keller <me@aviv.sh>
1 parent bb86521 commit fe06bf5

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(newAbortError());
229+
controller?.error(newAbortError());
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+
constduplex=newDuplex({
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+
constreader=readable.getReader();
273+
constwriter=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)