|
| 1 | +// Flags: --experimental-quic --no-warnings |
| 2 | + |
| 3 | +// Regression test: destroying a session with an error while its `closed` |
| 4 | +// promise is not being observed must NOT surface as an unhandled rejection. |
| 5 | + |
| 6 | +import{hasQuic,skip,mustCall,mustNotCall}from'../common/index.mjs'; |
| 7 | +import{subscribe,unsubscribe}from'node:diagnostics_channel'; |
| 8 | +import{setImmediateastick}from'node:timers/promises'; |
| 9 | + |
| 10 | +if(!hasQuic){ |
| 11 | +skip('QUIC is not enabled'); |
| 12 | +} |
| 13 | + |
| 14 | +const{ listen, connect }=awaitimport('../common/quic.mjs'); |
| 15 | + |
| 16 | +// Any unhandled rejection - e.g. an unobserved `closed` rejecting - fails. |
| 17 | +process.on('unhandledRejection',mustNotCall('unexpected unhandled rejection')); |
| 18 | + |
| 19 | +// We use the diagnostics channel to observe the error close without actually |
| 20 | +// observing session.closed (not listening is the whole point of the test): |
| 21 | +constserverErrored=Promise.withResolvers(); |
| 22 | +functiononSessionError(){ |
| 23 | +unsubscribe('quic.session.error',onSessionError); |
| 24 | +serverErrored.resolve(); |
| 25 | +} |
| 26 | +subscribe('quic.session.error',onSessionError); |
| 27 | + |
| 28 | +// The server session callback is left deliberately empty, so no response |
| 29 | +// is sent and closed remains unobserved: |
| 30 | +constserverEndpoint=awaitlisten(mustCall()); |
| 31 | + |
| 32 | +constclientSession=awaitconnect(serverEndpoint.address); |
| 33 | +awaitclientSession.opened; |
| 34 | + |
| 35 | +// Finish handshake before close: |
| 36 | +awaittick(); |
| 37 | + |
| 38 | +// Cleanly close from the client with an error code, so the server |
| 39 | +// receives a peer error close: |
| 40 | +awaitclientSession.close({code: 1}); |
| 41 | + |
| 42 | +// Wait until the server has processed the error close, plus another tick |
| 43 | +// to ensure unobserved promise rejection doesn't fire anywhere: |
| 44 | +awaitserverErrored.promise; |
| 45 | +awaittick(); |
| 46 | + |
| 47 | +awaitserverEndpoint.close(); |
0 commit comments