summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatteo Collina <hello@matteocollina.com>2021-11-22 10:32:02 +0100
committerMichaël Zasso <targos@protonmail.com>2021-11-26 15:36:32 +0100
commit534409d4e7a9e014aac628c93ac516d44da5b689 (patch)
tree8a8e5b63aeac9ddd42b3fe1b38eea3a0d8104d4b
parent90f35fc3292e35a6c6cfb6124c9a97d528a28cee (diff)
downloadnode-new-534409d4e7a9e014aac628c93ac516d44da5b689.tar.gz
stream: fix finished regression when working with legacy Stream
Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: https://github.com/nodejs/node/pull/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>
-rw-r--r--lib/internal/streams/end-of-stream.js4
-rw-r--r--test/parallel/test-stream-finished.js11
2 files changed, 12 insertions, 3 deletions
diff --git a/lib/internal/streams/end-of-stream.js b/lib/internal/streams/end-of-stream.js
index c224b44eac..ab60f5a7ea 100644
--- a/lib/internal/streams/end-of-stream.js
+++ b/lib/internal/streams/end-of-stream.js
@@ -165,13 +165,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)) {
diff --git a/test/parallel/test-stream-finished.js b/test/parallel/test-stream-finished.js
index 8ada0c4c34..570acded58 100644
--- a/test/parallel/test-stream-finished.js
+++ b/test/parallel/test-stream-finished.js
@@ -7,7 +7,8 @@ const {
Transform,
finished,
Duplex,
- PassThrough
+ PassThrough,
+ Stream,
} = require('stream');
const assert = require('assert');
const EE = require('events');
@@ -630,3 +631,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());
+}