Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http: do not blindly destroy UNIX domain sockets #15650

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,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();
}));
}));