-
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 should always emit close on finish #20043
Conversation
Rerun for node-test-commit-freebsd https://ci.nodejs.org/job/node-test-commit-freebsd/17043/ |
lib/_http_client.js
Outdated
if (res) { | ||
if (res.readable) { | ||
// Socket closed before we emitted 'end' below. | ||
res.emit('aborted'); |
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 !req.res.complete
condition is gone, is this wanted?
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.
No, definitely not.
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.
Is there any edit required here?
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.
It should have if (!req.res.complete) req.res.emit('aborted');
. I would check the rest too. There have been changes to that part of code since that original PR was started.
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.
Corrected in 8ffc3c7
lib/_http_client.js
Outdated
if (!req.res.complete) req.res.emit('aborted'); | ||
var res = req.res; | ||
res.on('end', function() { | ||
var res = req.res; |
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.
const
here.
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.
changed in 8ffc3c7
This will need CITGM run and also, if we don't have something like |
I think we need to handle the if (res) {
// *******
// NOTE: if `req.emit('response')` has been emitted we must always emit `aborted`, regardless of whether the response is readable or not.
// Socket closed before we emitted 'end' below.
if (!res.complete) {
res.emit('aborted');
}
// *******
if (res.readable) {
res.on('end', function() {
res.emit('close');
});
res.push(null);
} else {
res.emit('close');
}
} |
Should we make the order of This would avoid intermittent bugs in code that depend on the order. if (res) {
if (res.readable) {
// Socket closed before we emitted 'end' below.
if (!res.complete) {
res.emit('aborted');
}
req.emit('close'); // !! Emit close before or after aborted?
res.on('end', function() {
res.emit('close');
});
res.push(null);
} else {
req.emit('close'); // !!
res.emit('close');
}
} else if (!req.socket._hadError) {
// This socket error fired before we started to
// receive a response. The error needs to
// fire on the request.
req.socket._hadError = true;
req.emit('error', createHangUpError());
req.emit('close'); // !!
} else {
req.emit('close'); // !!
} |
#20075, feel free to cherry-pick |
Ping @trivikr |
Fixes: #17352
Original PR was posted at #17397
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes