mirror of
https://github.com/nodejs/node.git
synced 2025-05-04 15:02:25 +00:00

It's possible for the connections to take too long and since the server is already unrefed, the process will just exit. Instead adjust the test so that server unref only happens after all sessions have been successfuly established and unrefed. That still tests the same condition but will not fail under load. PR-URL: https://github.com/nodejs/node/pull/20772 Fixes: https://github.com/nodejs/node/issues/20705 Fixes: https://github.com/nodejs/node/issues/20750 Fixes: https://github.com/nodejs/node/issues/20850 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
61 lines
1.5 KiB
JavaScript
61 lines
1.5 KiB
JavaScript
'use strict';
|
|
// Flags: --expose-internals
|
|
|
|
// Tests that calling unref() on Http2Session:
|
|
// (1) Prevents it from keeping the process alive
|
|
// (2) Doesn't crash
|
|
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
const http2 = require('http2');
|
|
const Countdown = require('../common/countdown');
|
|
const makeDuplexPair = require('../common/duplexpair');
|
|
|
|
const server = http2.createServer();
|
|
const { clientSide, serverSide } = makeDuplexPair();
|
|
|
|
const counter = new Countdown(3, () => server.unref());
|
|
|
|
// 'session' event should be emitted 3 times:
|
|
// - the vanilla client
|
|
// - the destroyed client
|
|
// - manual 'connection' event emission with generic Duplex stream
|
|
server.on('session', common.mustCallAtLeast((session) => {
|
|
counter.dec();
|
|
session.unref();
|
|
}, 3));
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
const port = server.address().port;
|
|
|
|
// unref new client
|
|
{
|
|
const client = http2.connect(`http://localhost:${port}`);
|
|
client.unref();
|
|
}
|
|
|
|
// unref destroyed client
|
|
{
|
|
const client = http2.connect(`http://localhost:${port}`);
|
|
|
|
client.on('connect', common.mustCall(() => {
|
|
client.destroy();
|
|
client.unref();
|
|
}));
|
|
}
|
|
|
|
// unref destroyed client
|
|
{
|
|
const client = http2.connect(`http://localhost:${port}`, {
|
|
createConnection: common.mustCall(() => clientSide)
|
|
});
|
|
|
|
client.on('connect', common.mustCall(() => {
|
|
client.destroy();
|
|
client.unref();
|
|
}));
|
|
}
|
|
}));
|
|
server.emit('connection', serverSide);
|