Skip to content

Commit 86b2c2f

Browse files
committed
fix: Silence ECONNRESET errors after connection close
See also less/less.js#3693 Fixes tomas#391
1 parent 3c14264 commit 86b2c2f

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

lib/needle.js

+8
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,14 @@ Needle.prototype.send_request = function(count, method, uri, config, post_data,
489489
request.removeListener('error', had_error);
490490
out.done = true;
491491

492+
// An error can still be fired after closing. In particular, on macOS.
493+
// Adding an explicit abort() call resolves this without leaving a dangling
494+
// listener. See also:
495+
// - https://github.com/tomas/needle/issues/391
496+
// - https://github.com/less/less.js/issues/3693
497+
// - https://github.com/nodejs/node/issues/27916
498+
request.abort();
499+
492500
if (callback)
493501
return callback(err, resp, resp ? resp.body : undefined);
494502

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "needle",
3-
"version": "3.0.0",
3+
"version": "3.0.1",
44
"description": "The leanest and most handsome HTTP client in the Nodelands.",
55
"keywords": [
66
"http",

0 commit comments

Comments
 (0)