Skip to content

Commit

Permalink
fix: Silence ECONNRESET errors after connection close
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyparrish committed Mar 15, 2022
1 parent 3c14264 commit 86b2c2f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lib/needle.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,14 @@ Needle.prototype.send_request = function(count, method, uri, config, post_data,
request.removeListener('error', had_error);
out.done = true;

// An error can still be fired after closing. In particular, on macOS.
// Adding an explicit abort() call resolves this without leaving a dangling
// listener. See also:
// - https://github.com/tomas/needle/issues/391
// - https://github.com/less/less.js/issues/3693
// - https://github.com/nodejs/node/issues/27916
request.abort();

if (callback)
return callback(err, resp, resp ? resp.body : undefined);

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "needle",
"version": "3.0.0",
"version": "3.0.1",
"description": "The leanest and most handsome HTTP client in the Nodelands.",
"keywords": [
"http",
Expand Down

0 comments on commit 86b2c2f

Please sign in to comment.