Skip to content

Commit c514751

Browse files
davedoesdevdanielleadams
authored andcommitted
stream: don't push null from closed promise #42694
closed promise is subscribed to first so will be resolved first, before any read promise. This causes data after EOF error to be thrown. Remove the push null from the closed promise handler. The push null gets done from the read handler when it detects done. PR-URL: #45026 Fixes: #42694 Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 896b48b commit c514751

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

lib/internal/webstreams/adapters.js

-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ const {
3232
const {
3333
isDestroyed,
3434
isReadable,
35-
isReadableEnded,
3635
isWritable,
3736
isWritableEnded,
3837
} = require('internal/streams/utils');
@@ -528,8 +527,6 @@ function newStreamReadableFromReadableStream(readableStream, options = kEmptyObj
528527
reader.closed,
529528
() => {
530529
closed = true;
531-
if (!isReadableEnded(readable))
532-
readable.push(null);
533530
},
534531
(error) => {
535532
closed = true;
@@ -794,8 +791,6 @@ function newStreamDuplexFromReadableWritablePair(pair = kEmptyObject, options =
794791
reader.closed,
795792
() => {
796793
readableClosed = true;
797-
if (!isReadableEnded(duplex))
798-
duplex.push(null);
799794
},
800795
(error) => {
801796
writableClosed = true;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
const { mustCall } = require('../common');
3+
const { Readable, Duplex } = require('stream');
4+
const { strictEqual } = require('assert');
5+
6+
function start(controller) {
7+
controller.enqueue(new Uint8Array(1));
8+
controller.close();
9+
}
10+
11+
Readable.fromWeb(new ReadableStream({ start }))
12+
.on('data', mustCall((d) => {
13+
strictEqual(d.length, 1);
14+
}))
15+
.on('end', mustCall())
16+
.resume();
17+
18+
Duplex.fromWeb({
19+
readable: new ReadableStream({ start }),
20+
writable: new WritableStream({ write(chunk) {} })
21+
})
22+
.on('data', mustCall((d) => {
23+
strictEqual(d.length, 1);
24+
}))
25+
.on('end', mustCall())
26+
.resume();

0 commit comments

Comments
 (0)