Skip to content
This repository has been archived by the owner on Aug 31, 2018. It is now read-only.

Commit

Permalink
http: do not blindly destroy UNIX domain sockets
Browse files Browse the repository at this point in the history
`Connection: keep-alive` is now properly supported when making client
connections to UNIX domain sockets so `request.abort()` should not
blindly destroy the underlying socket.

PR-URL: nodejs/node#15650
Refs: nodejs/node#13214 (comment)
Reviewed-By: Anatoli Papirovski <[email protected]>
  • Loading branch information
lpinca authored and addaleax committed Oct 26, 2017
1 parent 4192ffa commit d203481
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,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');
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}));
}));

0 comments on commit d203481

Please sign in to comment.