0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-http-server-connection-list-when-close.js
theanarkh da3949cfd7
http: fix http server connection list when close
PR-URL: https://github.com/nodejs/node/pull/43949
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Feng Yu <F3n67u@outlook.com>
2022-07-24 15:06:24 +01:00

48 lines
1.1 KiB
JavaScript

'use strict';
const common = require('../common');
const http = require('http');
function request(server) {
http.get({
port: server.address().port,
path: '/',
}, (res) => {
res.resume();
});
}
{
const server = http.createServer((req, res) => {
// Hack to not remove parser out of server.connectionList
// See `freeParser` in _http_common.js
req.socket.parser.free = common.mustCall();
req.socket.on('close', common.mustCall(() => {
server.close();
}));
res.end('ok');
}).listen(0, common.mustCall(() => {
request(server);
}));
}
{
const server = http.createServer((req, res) => {
// See `freeParser` in _http_common.js
const { parser } = req.socket;
parser.free = common.mustCall(() => {
setImmediate(common.mustCall(() => {
parser.close();
}));
});
req.socket.on('close', common.mustCall(() => {
setImmediate(common.mustCall(() => {
server.close();
}));
}));
res.end('ok');
}).listen(0, common.mustCall(() => {
request(server);
}));
}