-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stream: fix finished regression when working with legacy Stream #40858
stream: fix finished regression when working with legacy Stream #40858
Conversation
@ronag do you know which of the PRs introduced this? |
Something is weird here. I want to understand why this happens. I’ll investigate today. |
The test exposes what would be the correct behavior when used on a legacy stream. As long as it pass that test we should be good. Note that this fix does not break any other test. |
@@ -630,3 +631,9 @@ testClosed((opts) => new Writable({ write() {}, ...opts })); | |||
})); | |||
})); | |||
} | |||
|
|||
{ | |||
// This case is needed to support the send module |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is a bit confusing because it sounds like send
is an internal module. Explaining what the test is checking for would be more useful than referencing a 3rd party module on npm, especially since as time goes on send
may change its implementation and this comment will be outdated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated, good idea.
ab9104f
to
fe41a9d
Compare
diff --git a/lib/internal/streams/end-of-stream.js b/lib/internal/streams/end-of-stream.js
index 91316f495c..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 || !isReadableNodeStream(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 This is a better fix. Basically what it says is that if we don't know (i.e. === null) then we don't call the callback (at the risk of deadlock). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my proposal above.
Signed-off-by: Matteo Collina <hello@matteocollina.com>
fe41a9d
to
144a216
Compare
@nodejs/streams |
Landed in cb75dec |
Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: #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>
Notable changes: build: * (SEMVER-MINOR) reset embedder string to "-node.0" (Michaël Zasso) #40488 deps: * (SEMVER-MINOR) disable trap handler for Windows cross-compiler (Michaël Zasso) #40488 * (SEMVER-MINOR) update V8 to 9.6.180.14 (Michaël Zasso) #40488 lib: * (SEMVER-MINOR) add reason to AbortSignal (James M Snell) #40807 src: * (SEMVER-MINOR) add x509.fingerprint512 to crypto module (3nprob) #39809 stream: * deprecate thenable support (Antoine du Hamel) #40860 * fix finished regression when working with legacy Stream (Matteo Collina) #40858 tools: * (SEMVER-MINOR) disable trap handler for Windows cross-compiler (Michaël Zasso) #40488 * (SEMVER-MINOR) update V8 gypfiles for 9.6 (Michaël Zasso) #40488 PR-URL: TODO
Notable changes: async_hooks: * (SEMVER-MINOR) expose async_wrap providers (Rafael Gonzaga) #40760 deps: * (SEMVER-MINOR) update V8 to 9.6.180.14 (Michaël Zasso) #40488 lib: * (SEMVER-MINOR) add reason to AbortSignal (James M Snell) #40807 src: * (SEMVER-MINOR) add x509.fingerprint512 to crypto module (3nprob) #39809 stream: * deprecate thenable support (Antoine du Hamel) #40860 * fix finished regression when working with legacy Stream (Matteo Collina) #40858 PR-URL: #40983
Notable changes: async_hooks: * (SEMVER-MINOR) expose async_wrap providers (Rafael Gonzaga) #40760 deps: * (SEMVER-MINOR) update V8 to 9.6.180.14 (Michaël Zasso) #40488 lib: * (SEMVER-MINOR) add reason to AbortSignal (James M Snell) #40807 src: * (SEMVER-MINOR) add x509.fingerprint512 to crypto module (3nprob) #39809 stream: * deprecate thenable support (Antoine du Hamel) #40860 * fix finished regression when working with legacy Stream (Matteo Collina) #40858 PR-URL: #40983
Notable changes: async_hooks: * (SEMVER-MINOR) expose async_wrap providers (Rafael Gonzaga) #40760 deps: * (SEMVER-MINOR) update V8 to 9.6.180.14 (Michaël Zasso) #40488 lib: * (SEMVER-MINOR) add reason to AbortSignal (James M Snell) #40807 src: * (SEMVER-MINOR) add x509.fingerprint512 to crypto module (3nprob) #39809 stream: * deprecate thenable support (Antoine du Hamel) #40860 * fix finished regression when working with legacy Stream (Matteo Collina) #40858 PR-URL: #40983
@mcollina can you create a backport PR for this if this also appears in 16.x? It broke a test in 16.x when trying to pull it in for the next release. |
Notable changes: async_hooks: * (SEMVER-MINOR) expose async_wrap providers (Rafael Gonzaga) nodejs#40760 deps: * (SEMVER-MINOR) update V8 to 9.6.180.14 (Michaël Zasso) nodejs#40488 lib: * (SEMVER-MINOR) add reason to AbortSignal (James M Snell) nodejs#40807 src: * (SEMVER-MINOR) add x509.fingerprint512 to crypto module (3nprob) nodejs#39809 stream: * deprecate thenable support (Antoine du Hamel) nodejs#40860 * fix finished regression when working with legacy Stream (Matteo Collina) nodejs#40858 PR-URL: nodejs#40983
This change does not backport cleanly and I don't think backporting it without the previous changes make sense. I have put the dont-land-x labels |
Fixes a regression introduced in Node v17 that made Fastify test fails.
The reason is that using
finished()
andpipeline()
with thesend
module started to error with "premature close" even if the stream did not close prematurely.