-
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
http: response does not emit error on premature close #28172
Comments
ping @Trott. Any feedback on this? |
/ping @nodejs/http, in particular on this:
|
Warning note in the doc would probably be relatively uncontroversial. If a change in behavior is deemed appropriate, we would probably need to wait for 13.0.0 anyway (and the warning can be removed at that time). |
PR-URL: #28262 Refs: #28172 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
PR-URL: #28262 Refs: #28172 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
@Trott How do I bring this issue forward? Or if it is being followed up where can I see that? Is there an agenda or something for node/http? If it's decided that we are not doing anything further that is also fine. I'd just like to know. |
Unfortunately @nodejs/http is one of the less active teams. (And one of the people on it that is, in fact, rather active in Node.js core happens to be taking some time off right now.) So it may be necessary to ping a bit more widely to get some activity on this. There's an unspoken rule that, in most cases, you don't ping @nodejs/collaborators without at least first pinging a more focused group. But since we've pinged that more focused group and haven't gotten much movement... @nodejs/collaborators This could use some comments, or even just emoji reactions to be honest. |
That’s unfortunate. As you might have noticed. I have quite a lot of things I would like to help sorting out in this area. |
@ronag feel free to ping me directly and I will do my best to try and review. |
I'm all in for making things less custom. However I'm a bit worried about the potential breakages caused by emitting a custom error in place of a Wdyt? |
I love this. |
It just happened to me, and it took me like 6 hours to find the issue. But Emitting |
@leodutra: Do you have an example and which version of node are you using? This should not be a problem if you are using Though I would still very much resolve this issue for the non |
I created a personal node-utils repo (which still don't have tests, but are being used every day on chatbots and some other PoCs). There is a node-utils/downloadFile.js When downloading files with GB, I noticed streams just stopped updating the progress bars and there started my investigation. Yesterday I tested a local version with abort, and it at least showed me the server dropped my connection... so the error is now being handled. This happened at the v12.12.0 and now on v13.0.1 for sure. |
FYI, I removed the |
@leodutra: This seems to be something in |
@leodutra: This seems to be something in I would avoid got and try something like https://gist.github.com/ronag/276513d01dbf5e551d73e89ff7f79dac If you want further help feel free to reach out to me on Slack. |
Yeah, I'm actually building a small request to stream with just the parts I need. I'll keep digging into it, I also need to clean the CLI bars for promise errors, in that particular source. Thanks for the source, @ronag. |
I did test a bit more and looks like I was wrong. When using I was able to see the error when I fixed the control of the CLI progress (the redraw was swallowing other console messages). But without Thanks for the help, @ronag. |
Hey, btw you could grab out the const { get } = require('http');
const { once } = require('events');
const req = get({ host: '127.0.0.1', port: 8080 });
const [ res ] = await once(req, 'response'); Which, handles |
Client responses aka. IncomingMessage emits 'aborted' instead of 'error' which causes confusion when the object is used as a regular stream, i.e. if functions working on streams are passed a client response object they might not work properly unless they take this into account. Refs: nodejs/web-server-frameworks#41 Fixes: nodejs#28172
Consider the following example:
Unintuitively, this will just hang and never finish (post #27984) or unexpectedly not fail and create an incomplete file (pre #27984). This is because we are not subscribing to
res.'aborted'
. If we have not yet received response we will getreq.'error'
withECONNRESET
and if we have received a response we only get anres.'aborted'
and no'error'
.In the above example (which is how I believe most people assume it should be) we have a problem. This has been a common source of error both for myself and other developers I have worked with (although in 99% of the time it's not a problem or not noticed).
Would it make sense to deprecate
aborted
and make the response object behave the same way as the request object, i.e. emit anerror
on premature close? Which I believe would be more consistent with the streams API.Alternatively, maybe a warning/note in the documentation or some other means of avoiding people making this mistake?
Currently the proper way to implement this is
either:Or post #27984:
The text was updated successfully, but these errors were encountered: