Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,19 @@ function socketCloseListener() {
// NOTE: It's important to get parser here, because it could be freed by
// the `socketOnData`.
var parser = socket.parser;
if (req.res && req.res.readable) {
// Socket closed before we emitted 'end' below.
if (!req.res.complete) req.res.emit('aborted');
var res = req.res;
res.on('end', function() {
var res = req.res;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed in 8ffc3c7

if (res) {
if (res.readable) {
// Socket closed before we emitted 'end' below.
res.emit('aborted');
Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, definitely not.

Copy link
Copy Markdown
Member Author

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?

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected in 8ffc3c7

res.on('end', function() {
this.emit('close');
});
res.push(null);
} else {
res.emit('close');
});
res.push(null);
} else if (!req.res && !req.socket._hadError) {
}
} else if (!req.socket._hadError) {
// This socket error fired before we started to
// receive a response. The error needs to
// fire on the request.
Expand Down
71 changes: 46 additions & 25 deletions test/parallel/test-http-response-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,50 @@
const common = require('../common');
const http = require('http');

const server = http.createServer(common.mustCall(function(req, res) {
res.writeHead(200);
res.write('a');
{
const server = http.createServer(
common.mustCall((req, res) => {
res.writeHead(200);
res.write('a');
})
);
server.listen(
0,
common.mustCall(() => {
http.get(
{ port: server.address().port },
common.mustCall((res) => {
res.on('data', common.mustCall(() => {
res.destroy();
}));
res.on('close', common.mustCall(() => {
server.close();
}));
})
);
})
);
}

req.on('close', common.mustCall(function() {
console.error('request aborted');
}));
res.on('close', common.mustCall(function() {
console.error('response aborted');
}));
}));
server.listen(0);

server.on('listening', function() {
console.error('make req');
http.get({
port: this.address().port
}, function(res) {
console.error('got res');
res.on('data', function(data) {
console.error('destroy res');
res.destroy();
server.close();
});
});
});
{
const server = http.createServer(
common.mustCall((req, res) => {
res.writeHead(200);
res.end('a');
})
);
server.listen(
0,
common.mustCall(() => {
http.get(
{ port: server.address().port },
common.mustCall((res) => {
res.on('close', common.mustCall(() => {
server.close();
}));
res.resume();
})
);
})
);
}