Skip to content

Commit

Permalink
fixup: reuse if not headersSent
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Mar 8, 2020
1 parent 0245e4e commit 6f11b24
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 1 addition & 4 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,7 @@ ClientRequest.prototype.destroy = function destroy(err) {
};

function _destroy(req, socket, err) {
// TODO (ronag): Check if socket was used at all (e.g. headersSent) and
// re-use it in that case. `req.socket` just checks whether the socket was
// assigned to the request and *might* have been used.
if (!req.agent || req.socket) {
if (!req.agent || req.headersSent) {
socket.destroy(err);
} else {
socket.emit('free');
Expand Down
4 changes: 4 additions & 0 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ function _writeRaw(data, encoding, callback) {
return false;
}

if (this.destroyed) {
return false;
}

if (typeof encoding === 'function') {
callback = encoding;
encoding = null;
Expand Down

0 comments on commit 6f11b24

Please sign in to comment.