Skip to content

Commit 534409d

Browse files
mcollinatargos
authored andcommitted
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 90f35fc commit 534409d

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
@@ -165,13 +165,13 @@ function eos(stream, options, callback) {
165165
} else if (
166166
!readable &&
167167
(!willEmitClose || isReadable(stream)) &&
168-
(writableFinished || !isWritable(stream))
168+
(writableFinished || isWritable(stream) === false)
169169
) {
170170
process.nextTick(onclose);
171171
} else if (
172172
!writable &&
173173
(!willEmitClose || isWritable(stream)) &&
174-
(readableFinished || !isReadable(stream))
174+
(readableFinished || isReadable(stream) === false)
175175
) {
176176
process.nextTick(onclose);
177177
} 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');
@@ -630,3 +631,11 @@ testClosed((opts) => new Writable({ write() {}, ...opts }));
630631
}));
631632
}));
632633
}
634+
635+
{
636+
// Legacy Streams do not inherit from Readable or Writable.
637+
// We cannot really assume anything about them, so we cannot close them
638+
// automatically.
639+
const s = new Stream();
640+
finished(s, common.mustNotCall());
641+
}

0 commit comments

Comments
 (0)