mirror of
https://github.com/nodejs/node.git
synced 2025-05-02 17:01:08 +00:00

Makes `Connection: keep-alive` behave correctly when making client connections to UNIX domain sockets. Prior to this, connections would never be re-used, but the keep-alive would cause the connections to stick around until they time out. This would lead to an eventual EMFILE error due to all the connections staying open. This was due to http.Agent not properly supporting UNIX domain sockets. PR-URL: https://github.com/nodejs/node/pull/13214 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
38 lines
839 B
JavaScript
38 lines
839 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const http = require('http');
|
|
|
|
const server = http.createServer((req, res) => res.end());
|
|
|
|
common.refreshTmpDir();
|
|
|
|
server.listen(common.PIPE, common.mustCall(() =>
|
|
asyncLoop(makeKeepAliveRequest, 10, common.mustCall(() =>
|
|
server.getConnections(common.mustCall((err, conns) => {
|
|
assert.ifError(err);
|
|
assert.strictEqual(conns, 1);
|
|
server.close();
|
|
}))
|
|
))
|
|
));
|
|
|
|
function asyncLoop(fn, times, cb) {
|
|
fn(function handler() {
|
|
if (--times) {
|
|
fn(handler);
|
|
} else {
|
|
cb();
|
|
}
|
|
});
|
|
}
|
|
function makeKeepAliveRequest(cb) {
|
|
http.get({
|
|
socketPath: common.PIPE,
|
|
headers: { connection: 'keep-alive' }
|
|
}, (res) => res.on('data', common.mustNotCall())
|
|
.on('error', assert.fail)
|
|
.on('end', cb)
|
|
);
|
|
}
|