diff --git a/lib/_http_client.js b/lib/_http_client.js index 4b7c755d634a55..98782e56e8ec25 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -659,7 +659,7 @@ ClientRequest.prototype.onSocket = function onSocket(socket) { function onSocketNT(req, socket) { if (req.aborted) { // If we were aborted while waiting for a socket, skip the whole thing. - if (req.socketPath || !req.agent) { + if (!req.agent) { socket.destroy(); } else { socket.emit('free'); diff --git a/test/parallel/test-http-abort-queued-2.js b/test/parallel/test-http-client-abort-keep-alive-queued-tcp-socket.js similarity index 100% rename from test/parallel/test-http-abort-queued-2.js rename to test/parallel/test-http-client-abort-keep-alive-queued-tcp-socket.js diff --git a/test/parallel/test-http-client-abort-keep-alive-queued-unix-socket.js b/test/parallel/test-http-client-abort-keep-alive-queued-unix-socket.js new file mode 100644 index 00000000000000..efcbfe8dc5846f --- /dev/null +++ b/test/parallel/test-http-client-abort-keep-alive-queued-unix-socket.js @@ -0,0 +1,38 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const http = require('http'); + +let socketsCreated = 0; + +class Agent extends http.Agent { + createConnection(options, oncreate) { + const socket = super.createConnection(options, oncreate); + socketsCreated++; + return socket; + } +} + +const server = http.createServer((req, res) => res.end()); + +const socketPath = common.PIPE; +common.refreshTmpDir(); + +server.listen(socketPath, common.mustCall(() => { + const agent = new Agent({ + keepAlive: true, + maxSockets: 1 + }); + + http.get({ agent, socketPath }, (res) => res.resume()); + + const req = http.get({ agent, socketPath }, common.mustNotCall()); + req.abort(); + + http.get({ agent, socketPath }, common.mustCall((res) => { + res.resume(); + assert.strictEqual(socketsCreated, 1); + agent.destroy(); + server.close(); + })); +}));