-
Notifications
You must be signed in to change notification settings - Fork 31k
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
request.abort()
still destroys the socket on a successful request
#32851
Comments
Please see sindresorhus/got#1154 (comment) Got calls |
So, if a request is in-progress, the only way with HTTP to abort the request is destroy the stream. But if a request is ended, and someone calls abort, there isn't anything to abort. What do you think should happen? throw an error, because it can't be aborted? a silent no-op? or what it does now, destroy the stream? |
I think a silent no-op would be a good choice. For example, Feel free to go with a major breaking way, throwing an error would also solve the issue. But I don't think it's a good idea to do so, because
Yup, |
Those are the same thing. Or at least, HTTP connections map 1:1 onto streams, and HTTP connections can only be aborted by destroying the underlying stream. Also, streams only have a .destroy(), not an abort(), so "abort the stream" means "destroy the stream" (if it means anything). In other words, abort === destroy, with the possible optimization that if a request is not in flight, it could possibly no-op or throw. But consistency is nice, rather than having APIs where the behaviour depends on the exact point in the HTTP state machine the client request is at the point of the API call, if they always do the same thing, its easier to reason about. IMO, of course. |
According to the HTTP/1.1 implementation, yes. But keep in mind example HTTP/2 introduces streams, and in that case streams !== connections.
Agreed.
It depends on how you interpret this. If you want full consistency, then you either need to always destroy the stream or throw an error. On the other hand, you just need to abort the pending request, and since the request has been completed you want to reuse the socket later (assuming you're having a keepalive agent). |
This should be possible to fix. This condition needs to be improved to be less strict. https://github.com/nodejs/node/blob/master/lib/_http_client.js#L374 |
Ok, I'll send a PR. |
Hm, actually this might be more complicated than that. Might have to interact with Might need some more significant refactoring to fix this in a nice way. Unsure. |
@szmarczak: #33120 will probably fix this. I'm a little short on time right now. If you want to help out building some tests would be appreciated. |
Calling destroy() on a completed ClientRequest, i.e. once 'close' will be emitted should be a noop. Also before emitting 'close' destroyed === true. Fixes: nodejs#32851
Calling destroy() on a completed ClientRequest, i.e. once 'close' will be emitted should be a noop. Also before emitting 'close' destroyed === true. Fixes: #32851 PR-URL: #33120 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
Linux solus 5.5.11-151.current #1 SMP PREEMPT Tue Mar 24 18:06:46 UTC 2020 x86_64 GNU/Linux
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
Always.
What is the expected behavior?
The socket should be still alive.
What do you see instead?
The socket is destroyed.
The text was updated successfully, but these errors were encountered: