-
Notifications
You must be signed in to change notification settings - Fork 555
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
Empty fetch() response with 'Content-Encoding: br' header causes a crash due to unhandled error event in BrotliDecompress #3616
Comments
@ronag it seems like pipeline isn't forwarding the error here? This fixes it: diff --git a/lib/web/fetch/index.js b/lib/web/fetch/index.js
index 435eafdf..9a26977e 100644
--- a/lib/web/fetch/index.js
+++ b/lib/web/fetch/index.js
@@ -2153,7 +2153,7 @@ async function httpNetworkFetch (
} else if (coding === 'deflate') {
decoders.push(createInflate())
} else if (coding === 'br') {
- decoders.push(zlib.createBrotliDecompress())
+ decoders.push(zlib.createBrotliDecompress().on('error', noop))
} else {
decoders.length = 0
break |
import { pipeline, Readable } from 'node:stream'
import { createBrotliDecompress } from 'node:zlib'
pipeline(new Readable({
read () {
this.push(null)
}
}), createBrotliDecompress(), () => {}) reproducible without fetch |
to avoid possible exception due to encoding. (Probably a node bug, reported in nodejs/undici#3616) Replace abort with cancel, which is the recommended way to cancel the response. fixes #687
That example is incorrect as pipeline(new Readable({
read () {
this.push(null)
}
}), createBrotliDecompress(), () => {}).on('error, () => {}) |
As far as I can tell it is forwarding it, it's just not handled... |
Seems to me related to either fetch or WebStreams. |
Shouldn't the error be passed to the callback (last parameter)? Maybe I'm misunderstanding it? This example is what I'm confused about: https://nodejs.org/api/stream.html#streampipelinestreams-callback |
Not if the last stream passed is readable. |
provided PR #3620 |
Version
22.6.0, 20.9.0, 20.17.0
Platform
No response
Subsystem
No response
What steps will reproduce the bug?
An empty response with
Content-Encoding: br
results in an error if the response is canceled, not consumed, consumed by a stream.This can be reproduced with a server:
and then a client calling:
Although
done
will be printed, an exception will be thrown afterwards:How often does it reproduce? Is there a required condition?
This happens whenever the stream is not immediately consumed
The following will cause a crash:
The following will NOT cause a crash, because the body is immediately consumed:
What is the expected behavior? Why is that the expected behavior?
fetch() should not a cause an unhandled error that crashes node, even if the response body is never consumed, especially since it is empty. This is the behavior with other compression types, such as
Content-Encoding: gzip
.What do you see instead?
fetch() causes node to crash due to an unhandled error event from BrotliDecompress
Additional information
No response
The text was updated successfully, but these errors were encountered: