You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Non-GET http2 requests without a body hang indefninitely #2589
When using fetch to make non-GET/HEAD http2 requests, the function call hangs indefinitely. Passing in an empty string in place of the body fixes this issue.
Reproducible By
The following js script triggers the issue on undici v6.2.1
@timursevimli I believe the problem you're facing is not a bug, and not related to the problem I've posted in the OP. Try passing in your object as data not body, or stringifiying the JSON yourself and setting the respective content-type if using body.
Approach: I suggest a tweak in the undici library where we can specifically check for an empty body. This adjustment would involve handling the content-length header appropriately.
Adjusting Fetch Options:
Resolution Approach: To address the issue, consider adjusting the fetch options. Explicitly include an empty body in the request.
// Example Code Snippetconstres=awaitfetch("https://google.com",{dispatcher: client,baseURL: 'https://google.com',url: 'https://google.com/',method: "POST",// Include an empty bodybody: ''});
This modification ensures that the function call sends the request with an empty body, effectively resolving the hanging behavior.
changed the title [-]fetch hangs on non-GET http2 requests without a body[/-][+]Non-GET http2 requests without a body hang indefninitely[/+]on Jan 22, 2024
Activity
metcoder95 commentedon Jan 4, 2024
Hey! Thanks for the report
I believe this should be scope to validate wether or not there's a body at all being sent.
Would you like to submit a PR?
ronag commentedon Jan 4, 2024
I'm confused. It should be possible to send a fetch without body? Also this sounds like we are missing something in the spec language? @KhafraDev
KhafraDev commentedon Jan 4, 2024
this isn't an issue with fetch afaict
timursevimli commentedon Jan 5, 2024
While I was trying to investigate this problem, I discovered a completely different problem.
When we pass body the following object appears:
(For this output I used output a variable called finalBody in undici/lib/fetch/request.js:505)
Well, if we pass an object to body, then we get the following output:
In this case, regardless of the size of our object, length will always be 15 and source will be incorrect.
ktaekwon000 commentedon Jan 5, 2024
@timursevimli I believe the problem you're facing is not a bug, and not related to the problem I've posted in the OP. Try passing in your object as
datanotbody, or stringifiying the JSON yourself and setting the respective content-type if usingbody.Piyush-Kumar-Ghosh commentedon Jan 8, 2024
Proposed Solutions:
Enhancing undici Library:
lib/fetch.jsAdjusting Fetch Options:
fetchoptions. Explicitly include an empty body in the request.This modification ensures that the function call sends the request with an empty body, effectively resolving the hanging behavior.
mcollina commentedon Jan 8, 2024
Given this works with HTTP/1.1, it's not a bug in
fetch()but in our HTTP/2 implementation.[-]fetch hangs on non-GET http2 requests without a body[/-][+]Non-GET http2 requests without a body hang indefninitely[/+]ktaekwon000 commentedon Jan 22, 2024
I can verify that the script in the OP runs without issues on v6.4.0 of undici. Thanks everyone for the comments and @timursevimli for the PR!
0.0.143 - replace custom HTTP/2 fetch with undici, add memory logging