|
| 1 | +// Flags: --experimental-quic --no-warnings |
| 2 | + |
| 3 | +// Regression test: HTTP/3 server must not crash when a session is closed |
| 4 | +// before the H3 application is fully started (control streams bound). |
| 5 | +// Previously, closing such a session would call nghttp3_conn_shutdown on |
| 6 | +// an H3 connection whose control streams were never bound, causing an |
| 7 | +// assertion failure in nghttp3 (conn->tx.ctrl != NULL). |
| 8 | +// |
| 9 | +// The test creates an H3 server and a client that immediately closes the |
| 10 | +// session before the handshake completes. The server creates the H3 |
| 11 | +// application during ALPN negotiation, but Start() (which binds control |
| 12 | +// streams) hasn't been called yet when the session is torn down. |
| 13 | +// The server must handle this gracefully without crashing. |
| 14 | + |
| 15 | +import { hasQuic, skip, mustNotCall } from '../common/index.mjs'; |
| 16 | +import { setTimeout } from 'node:timers/promises'; |
| 17 | +import * as fixtures from '../common/fixtures.mjs'; |
| 18 | + |
| 19 | +const { readKey } = fixtures; |
| 20 | + |
| 21 | +if (!hasQuic) { |
| 22 | + skip('QUIC is not enabled'); |
| 23 | +} |
| 24 | + |
| 25 | +const { listen, connect } = await import('node:quic'); |
| 26 | +const { createPrivateKey } = await import('node:crypto'); |
| 27 | + |
| 28 | +const key = createPrivateKey(readKey('agent1-key.pem')); |
| 29 | +const cert = readKey('agent1-cert.pem'); |
| 30 | + |
| 31 | +const serverEndpoint = await listen(async (serverSession) => { |
| 32 | + await serverSession.closed; |
| 33 | +}, { |
| 34 | + sni: { '*': { keys: [key], certs: [cert] } }, |
| 35 | + onheaders: mustNotCall(), |
| 36 | +}); |
| 37 | + |
| 38 | +// Connect then immediately close the session before the handshake completes. |
| 39 | +// This exercises the H3 shutdown path on the server while the H3 application |
| 40 | +// exists but hasn't started (control streams not yet bound). |
| 41 | +const clientSession = await connect(serverEndpoint.address, { |
| 42 | + servername: 'localhost', |
| 43 | + // h3 ALPN — must match the server so the H3 application is selected |
| 44 | + // on the server side before we tear it down. |
| 45 | +}); |
| 46 | + |
| 47 | +// Close immediately — don't wait for handshake. |
| 48 | +await clientSession.close(); |
| 49 | + |
| 50 | +// Give the server time to process the close and tear down the session. |
| 51 | +await setTimeout(500); |
| 52 | + |
| 53 | +// The critical assertion: reaching this point without a crash means the |
| 54 | +// server correctly handled the H3 shutdown before control streams were |
| 55 | +// bound. Verify the endpoint is still alive by closing it gracefully. |
| 56 | +await serverEndpoint.close(); |
0 commit comments