-
Notifications
You must be signed in to change notification settings - Fork 11
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
[node v20] Fetch with default context and HTTP/1.1 server hangs when not reading the response body #472
Comments
Thanks for reporting this issue and providing detailed instructions to reproduce it! The observed behavior is due to internal changes in Node's
Workarounds:
import { h1 } from '@adobe/fetch';
const { fetch } = h1();
|
Found the root cause. It's unrelated to
Some links: |
The hanging process when not reading the response (due to dangling sockets) is not specific to import https from 'node:https';
const url = new URL('https://the-internet.herokuapp.com/status_codes/500');
let req = https.request(url, (res) => {
console.log('req #1 statusCode:', res.statusCode);
// don't read body
// res.on('data', (d) => {
// process.stdout.write(d);
// });
});
req.end();
req = https.request(url, (res) => {
console.log('req #2 statusCode:', res.statusCode);
// don't read body
// res.on('data', (d) => {
// process.stdout.write(d);
// });
});
req.end(); If the response body is consumed or when using Node.js v18 the process terminates normally. |
I can confirm with curl that |
fixed by #476 |
Description
For http2, the stream doesn't get closed if the body is not read. Not reading the body is common sometimes for error cases in nodejs and this error doesn't happen if you use HTTP1 or other node fetch implementations like
node-fetch
. Leaving connections open can result in hanging in tests or extreme cases if the service calls a lot of HTTP requests that fail, it could result inMy suggestion is to have some warning about this and suggest to always read the body in http2.
To Reproduce
This script displays hanging when running locally with any value of times >1. (node v20)
node-fetch doesn't hang in this case:
However if you just switch the body read to before the error check, it works fine
Expected behavior
adobe/fetch docs should call this out, along the lines of “you normally don’t have to do this with other fetch implementations, but in our case cleanup only happens after the response body is consumed. if not, leaks can happen. make sure to always consume the response in all cases (error or not) with await response.body() [or
response.text()
]”Version:
v4.1.2
The text was updated successfully, but these errors were encountered: