mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
4267b92604
PR-URL: https://github.com/nodejs/node/pull/43522 Fixes: https://github.com/nodejs/node/issues/37184 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
39 lines
895 B
JavaScript
39 lines
895 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const http = require('http');
|
|
|
|
const server = http.createServer((req, res) => res.end());
|
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
tmpdir.refresh();
|
|
|
|
server.listen(common.PIPE, common.mustCall(() =>
|
|
asyncLoop(makeKeepAliveRequest, 10, common.mustCall(() =>
|
|
server.getConnections(common.mustSucceed((conns) => {
|
|
assert.strictEqual(conns, 1);
|
|
server.close();
|
|
}))
|
|
))
|
|
));
|
|
|
|
function asyncLoop(fn, times, cb) {
|
|
fn(function handler() {
|
|
if (--times) {
|
|
setTimeout(() => fn(handler), common.platformTimeout(10));
|
|
} 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)
|
|
);
|
|
}
|