Skip to content

Commit

Permalink
stream: fix finished regression when working with legacy Stream
Browse files Browse the repository at this point in the history
Signed-off-by: Matteo Collina <hello@matteocollina.com>

PR-URL: nodejs#40858
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
mcollina authored and sbaayel committed Jun 29, 2023
1 parent 02ea36a commit 3b5ed2a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/internal/streams/end-of-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@ function eos(stream, options, callback) {
} else if (
!readable &&
(!willEmitClose || isReadable(stream)) &&
(writableFinished || !isWritable(stream))
(writableFinished || isWritable(stream) === false)
) {
process.nextTick(onclose);
} else if (
!writable &&
(!willEmitClose || isWritable(stream)) &&
(readableFinished || !isReadable(stream))
(readableFinished || isReadable(stream) === false)
) {
process.nextTick(onclose);
} else if ((rState && stream.req && stream.aborted)) {
Expand Down
11 changes: 10 additions & 1 deletion test/parallel/test-stream-finished.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const {
Transform,
finished,
Duplex,
PassThrough
PassThrough,
Stream,
} = require('stream');
const assert = require('assert');
const EE = require('events');
Expand Down Expand Up @@ -634,3 +635,11 @@ testClosed((opts) => new Writable({ write() {}, ...opts }));
}));
}));
}

{
// Legacy Streams do not inherit from Readable or Writable.
// We cannot really assume anything about them, so we cannot close them
// automatically.
const s = new Stream();
finished(s, common.mustNotCall());
}

0 comments on commit 3b5ed2a

Please sign in to comment.