-
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
Readable.fromWeb
is never finished
#49233
Comments
Define "crashes"? I'd like to see the stack trace or whatever you get. |
Node.js exits during executing this line: So I think that site has something unexpected (SSL certificate, server settings, ...) which triggers an exception not handled correctly and node.js exits abruptly. Is there any option to enable some node.js logging to inspect what is going on? |
Ah, okay. I think your report is a duplicate of #48466 and one or two other similar reports (that I can't find right now but I remember commenting on them. They're in the bug tracker... somewhere.) If you agree it's the same bug, then please go ahead and close this issue. |
The linked issue, if I understand correctly, causes an exiting the Node.js when the stream is consumed, but it is interrupted before calling close() method. Ok, this should be fixed. But there is another issue here. Why that stream interruption is not detected and the corresponding exception thrown, so it could be processed in my catch block? When accessing different URLs I can see many errors (certificate problems, timeouts) so I would expect to handle such interruption events in the same way. From the linked issue I deduce here the server closes the connection before sending the response. If so, it should be handled gracefully. But I can be wrong. I am not an experienced Node.js user to be able to dig into it more deeply. |
Most likely because the promise returned by ESM versionimport fs from "node:fs";
import { Readable } from "node:stream";
import { finished } from "node:stream/promises";
async function saveURLToFile(url, path) {
try {
const response = await fetch(url);
const fileStream = fs.createWriteStream(path);
await finished(Readable.fromWeb(response.body).pipe(fileStream));
} catch (err) {
console.log(err);
}
}
await saveURLToFile(
"http://www.milicovice.cz/",
new URL("./output.html", import.meta.url)
); $ node entry.mjs
$ echo $?
13 |
Readable.fromWeb
is never finished
I've rename the issue because there's no crash. @nodejs/whatwg-stream can you comment wether the current behavior is expected or it should be fixed? |
I'm not sure what is the actual issue. The following code works correctly on my machine (it prints const fs = require("fs")
const path = require("path")
const { Readable } = require("stream")
const { finished } = require("stream/promises")
async function saveURLToFile(url, path) {
try {
const response = await fetch(url)
const fileStream = fs.createWriteStream(path)
await finished(Readable.fromWeb(response.body).pipe(fileStream))
console.log('finished')
} catch (err) {
console.log(err)
}
}
saveURLToFile("http://www.milicovice.cz/", path.resolve(__dirname, "output.html")) @nodejs/undici I think I saw this problem already but I can't find an issue/pr. |
@mcollina That code still doesn't work on my laptop in Nodejs v18.17.1 on Win64 Pro (10.0.22621 Build 22621). But now this stacktrace is printed:
|
Exactly the same stracktrace I am getting also when saving the content for http://www.hornimarsov.cz/ so this issue is not isolated for the above single server URL. |
Something that would be really useful to debug this is to have a complete reproduction, i.e. a local Node.js server that can trigger this problem in the client. The bug might even be Windows specific. |
Couldn't find it, the closest one was nodejs/undici#2026 |
FWIW when I run the snippet in #49233 (comment) using the latest
|
Funny insight: right now I can reproduce your results @aduh95. My understanding is that our decompression algorithm is failing to decompress that payload: this is likely some kind of incompatibility with the meaning of |
Wappalyzer plugin + Dev Tools reports this set of server details http://www.milicovice.cz/ http://www.hornimarsov.cz/ Each server's root cause will most likely differ as server configurations differ significantly. Something about compression on IIS is here https://learn.microsoft.com/en-us/iis/extensions/iis-compression/iis-compression-overview There is stated two libs are available for the deflate compression, gzip.dll and iiszlib.dll. The second is not OOTB, but is more efficient and has better dynamic compression support. But it could explain incompatibilities. |
I think this is due to nodejs/undici#2128. |
I've investigated this issue with Node v18.20.2, v20.16.0 and v22.9.0. Both v20 and v22 worked as expected. |
Per the comment above. See nodejs/undici#2650 |
Thanks a lot for managing the fix. I downloaded 20.17.0 LTS (Win MSI installer) and ran the script again. The task is now completed without any issues. Making this functionality more robust (i.e. supporting even obscure old sites) will eliminate headaches for many future developers. Kudos to all! |
Version
v18.17.1
Platform
Win64
Subsystem
No response
What steps will reproduce the bug?
Run this script:
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
The content (HTML page) is stored to the file.
What do you see instead?
The node crashes.
Additional information
This method works for other sites. It is unclear why this one is problematic. That error is apparently uncaught by the catch block.
This site belongs to the municipality of a small village. Please minimize the traffic (during testing) to a minimum. Thanks.
The text was updated successfully, but these errors were encountered: