Skip to content

Commit cb75dec

Browse files
authored
stream: fix finished regression when working with legacy Stream
Signed-off-by: Matteo Collina <[email protected]> PR-URL: #40858 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent 8a03482 commit cb75dec

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/internal/streams/end-of-stream.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,13 @@ function eos(stream, options, callback) {
167167
} else if (
168168
!readable &&
169169
(!willEmitClose || isReadable(stream)) &&
170-
(writableFinished || !isWritable(stream))
170+
(writableFinished || isWritable(stream) === false)
171171
) {
172172
process.nextTick(onclose);
173173
} else if (
174174
!writable &&
175175
(!willEmitClose || isWritable(stream)) &&
176-
(readableFinished || !isReadable(stream))
176+
(readableFinished || isReadable(stream) === false)
177177
) {
178178
process.nextTick(onclose);
179179
} else if ((rState && stream.req && stream.aborted)) {

test/parallel/test-stream-finished.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const {
77
Transform,
88
finished,
99
Duplex,
10-
PassThrough
10+
PassThrough,
11+
Stream,
1112
} = require('stream');
1213
const assert = require('assert');
1314
const EE = require('events');
@@ -634,3 +635,11 @@ testClosed((opts) => new Writable({ write() {}, ...opts }));
634635
}));
635636
}));
636637
}
638+
639+
{
640+
// Legacy Streams do not inherit from Readable or Writable.
641+
// We cannot really assume anything about them, so we cannot close them
642+
// automatically.
643+
const s = new Stream();
644+
finished(s, common.mustNotCall());
645+
}

0 commit comments

Comments
 (0)