deno: Consuming certain HTTPS fetch responses fails with "unexpected end of file"
const res = await fetch("https://wpt.live/resources/testharness.js");
await res.text();
Uncaught Error: request or response body error: error reading a body from connection: unexpected end of file
at async Object.pull (deno:ext/fetch/26_fetch.js:108:24)
This doesn’t fail with every HTTPS response – https://wpt.live/resources/ works, for example – but it seems to be consistent when it does. It doesn’t happen with HTTP at all.
This seems to have been introduced in the upgrade to rustls 0.20 in #12488.
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 3
- Comments: 18 (5 by maintainers)
Commits related to this issue
- Revert "chore: upgrade to rustls 0.20 (#12488)" This reverts commit a2f1357fe81fe212451567cc433c0e6b4a85edc5. Closes #13058. — committed to andreubotella/deno by deleted user 3 years ago
As a workaround, I’m thinking about just retrying the fetch when the bug occurs. Something like this: https://dev.to/ycmjason/javascript-fetch-retry-upon-failure-3p6g
For me, the bug rarely happens twice in a row, so maybe I can get past it by just retrying x number of times.
Update This workaround/hack worked great. The bug still occurred 7 times out of 207 fetches, but it never occurred twice in a row in my test. Although I coded it to re-try up to 10 times, each time the bug occurred (those 7 times), on the very next try the fetch succeeded.
All I did to my code was add this function at the top, and then I used
fetch_retry()instead offetch()throughout the entire script.The function above was written by Jason Yu. The only modifications I made to it, were (1) I made
ndefault to 10 (tries), and (2) I added aconsole.log()so I could see when the re-tries occurred (oh yeah, and I changed white-space a bit). To see Jason Yu’s function without my modifications, go here.In summary, I consider this a terrible bug that should rank very high on Deno’s ToDo list. Fetch is a fundamental utility that should be rock solid in each deno release. However, I’m glad this bug happened: because it caused me to make my own code way more robust (with or without this bug).
No fix? not even some monkey-patch?
Like what do I do now? Re-write the entire project in another language? 😕
@Lonniebiz I used this workaround and tried fetching the data 100 times, but the error occurs every single time for me. Are there any other workarounds/fixes available?
This is an upstream bug: rustls/hyper-rustls#162
Guys, I’m looking for practical solutions that I can implement until this is fixed.
For example, I running deno verison 1.22.2 on this project. Does anyone know which version of Deno precedes this bug? Perhaps I can downgrade to a version of deno where this bug goes away, and later upgrade to the latest deno once it is confirmed fix.
It is my understanding that the reason Deno is throwing this error, is because the web server I’m requesting from isn’t always “sending a CloseNotify alert before closing their response stream”.
I tire very quickly of frameworks that prioritize correctness over robustness. Something that’s not correct is only worthy of a warning if that lack of correctness can be ignored to achieve robustness.
What I assume is the same issue is also causing Deno to fail to cache deps or run type checks on GitHub Actions CI, which has broken my app’s builds. For some reason it doesn’t seem to happen on my local MacOS Deno, even though it’s the same version.
and
I have re-run the tests several times and they fail similarly each time, though often on a different file.
This is Deno 1.17.0 running on GitHub Actions default ubuntu runner.