Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Tweak new H2 shutdown test towards reliable ordering & client shutdown
Currently the test fails only in a couple of environments (Mac & ASan)
reliably, even though it passes reliably in all others. The failures are
due to emitted errors on the client H2 stream (not the focus of this
test). I'm hoping here that that's due to a timing different in those
environments, and scheduling the shutdown like this instead will
guarantee the order so that doesn't happen any more.
  • Loading branch information
pimterry committed Aug 28, 2023
commit 87ceb7eeea01dc52542236241fe613f4961aabf8
31 changes: 20 additions & 11 deletions test/parallel/test-http2-socket-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ const tlsOptions = {
ALPNProtocols: ['h2']
};

// Create a net server that upgrades sockets to HTTP/2 manually, but with two
// different shutdown timeouts: a short socket timeout, and a longer H2 session timeout.
// Since the only request is complete, the session should shutdown cleanly when the
// socket shuts down (and should _not_ segfault, as it does in Node v20.5.1)
// Create a net server that upgrades sockets to HTTP/2 manually, handles the
// request, and then shuts down via a short socket timeout and a longer H2 session
// timeout. This is an unconventional way to shut down a session (the underlying
// socket closing first) but it should work - critically, it shouldn't segfault
// (as it did until Node v20.5.1).

const netServer = net.createServer((socket) => {
setTimeout(() => {
socket.destroy();
}, 10);
let serverRawSocket;
let serverH2Session;

const netServer = net.createServer((socket) => {
serverRawSocket = socket;
h2Server.emit('connection', socket);
});

Expand All @@ -33,9 +34,7 @@ const h2Server = h2.createSecureServer(tlsOptions, (req, res) => {
});

h2Server.on('session', (session) => {
setTimeout(() => {
session.close();
}, 20);
serverH2Session = session;
});

netServer.listen(0, common.mustCall(() => {
Expand All @@ -54,5 +53,15 @@ netServer.listen(0, common.mustCall(() => {

req.on('response', common.mustCall((response) => {
assert.strictEqual(response[':status'], 200);

// Asynchronously shut down the server's connections after the response,
// but not in the order it typically expects:
setTimeout(() => {
serverRawSocket.destroy();

setTimeout(() => {
serverH2Session.close();
}, 10);
}, 10);
}));
}));