Skip to content
Closed
Changes from all commits
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
http: http client response should always emit close when finished
  • Loading branch information
ronag committed Dec 13, 2017
commit 774a14c3bf8558a57b68c085ce6e17d18cd6ceb9
20 changes: 12 additions & 8 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,15 +346,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.
req.res.emit('aborted');
var res = req.res;
res.on('end', function() {
var res = req.res;
if (res) {
if (res.readable) {
// Socket closed before we emitted 'end' below.
res.emit('aborted');
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