-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
[x] http: client destroy stream #29192
Conversation
595b846
to
4a82370
Compare
9223798
to
f904ea8
Compare
5f4f9d6
to
19425c2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
cc @nodejs/tsc |
(Needs a rebase.) |
822a66e
to
f4bf6d2
Compare
@Trott rebased |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some more tests about this behavior change?
Not sure what that would test. I'll think about it and give it a try. |
} else if (this[kWritableState].socketPending) { | ||
// In the event that we don't have a socket, we will pop out of | ||
// the request queue through handling in onSocket. | ||
this[kWritableState].destroyCallback = (er) => cb(er || err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to wait for the 'socket'
event to be emitted instead of adding one more state parameter: https://nodejs.org/api/http.html#http_event_socket.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That won't work, the socket event is not always emitted. See the error case in oncreate
, i.e. close to where your other comment is.
The error from oncreate
needs to be properly forwarded to the _destroy
callback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a user perspective, I think we should be swallowing that error if destroy()
was called before hand.
Do we test that calling destroy()
before we have a socket actually calls socket.destroy()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be further refactored if/once #29656 is merged. But it basically does the same thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we test that calling destroy() before we have a socket actually calls socket.destroy()?
Test added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The possibility of deadlocks/having a callback not called in the destroy process makes me nervous. The current logic is significantly simpler, even if less correct, and I feel this might bite us in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The possibility of deadlocks/having a callback not called in the destroy process makes me nervous.
That's the way Node works? This is not the only case? What can we do to make you less nervous? More tests?
The current logic is significantly simpler, even if less correct, and I feel this might bite us in the future.
I strongly disagree with this. In my opinion this kind of mentality will stagnate the project. Shouldn't we strive after correctness and consistency?
We have similar scenarios in a lot of different places and I have pending PR's (e.g. #29656) with efforts on this.
If this (swallow error) is the way we go then I'd like to ask #29197 to be reconsidered (to "no error after destroy") in order to achieve some form of consistency. Otherwise, we will never have "correct" code even in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we strive after correctness and consistency?
No. We should strive to not break current users, and then consistency. Correctness it's extremely hard to measure because there are no specifications for any of this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should strive to not break current users
How does this break current users?
22e5830
to
66e6272
Compare
I've tried adding more test for what make sense. However, most of these changes are refactoring in nature as well as re and proper use of existing framework. |
1016ea1
to
09d15d5
Compare
09d15d5
to
8441fc5
Compare
8441fc5
to
1483ef1
Compare
This PR can probably be easier implemented with #29656 |
This is blocked by #29656 |
This PR tries to re-use the destroy logic from streams. One small step towards making
ClientRequest
more stream-like.Based on #28683. Since it's close to being merged I don't want to complicate it further.Unlike #28683. Doesn't currently swallow errors. But will only emit one error after
deestroy()
.Refs: #28686
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes