mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 10:15:07 +08:00
Signed-off-by: James M Snell <jasnell@gmail.com> Assisted-by: Opencode:Opus 4.6 PR-URL: https://github.com/nodejs/node/pull/62876 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Robert Nagy <ronagy@icloud.com>
42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
// Flags: --experimental-quic --no-warnings
|
|
|
|
// Test: concurrent close() from both client and server.
|
|
// Both sides initiate close simultaneously. Neither should crash
|
|
// and both closed promises should settle.
|
|
|
|
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
|
|
|
if (!hasQuic) {
|
|
skip('QUIC is not enabled');
|
|
}
|
|
|
|
const { listen, connect } = await import('../common/quic.mjs');
|
|
|
|
const serverDone = Promise.withResolvers();
|
|
|
|
const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
|
serverSession.onstream = mustCall(async (stream) => {
|
|
// Once the stream arrives, both sides close simultaneously.
|
|
stream.writer.endSync();
|
|
await stream.closed;
|
|
serverSession.close();
|
|
});
|
|
await serverSession.closed;
|
|
serverDone.resolve();
|
|
}));
|
|
|
|
const clientSession = await connect(serverEndpoint.address);
|
|
await clientSession.opened;
|
|
|
|
// Open a stream so the server session has work, then close from both sides.
|
|
const stream = await clientSession.createBidirectionalStream();
|
|
stream.writer.endSync();
|
|
for await (const _ of stream) { /* drain */ } // eslint-disable-line no-unused-vars
|
|
await stream.closed;
|
|
|
|
// Client close happens around the same time as server close above.
|
|
await clientSession.close();
|
|
|
|
await serverDone.promise;
|
|
await serverEndpoint.close();
|