diff --git a/lib/needle.js b/lib/needle.js index b56c8f66b..2652827a5 100644 --- a/lib/needle.js +++ b/lib/needle.js @@ -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); diff --git a/package-lock.json b/package-lock.json index 26fd4c6af..cfe835af0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "needle", - "version": "3.0.0", + "version": "3.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index aac6aa7e8..ee92ee9c4 100644 --- a/package.json +++ b/package.json @@ -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",