mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00

Although most of the time openStream will be able to create the stream immediately, when a stream is opened before the handshake is complete we have to wait for the handshake to be complete before continuing. PR-URL: https://github.com/nodejs/node/pull/34351 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
51 lines
1.3 KiB
JavaScript
51 lines
1.3 KiB
JavaScript
// Flags: --no-warnings
|
|
'use strict';
|
|
const common = require('../common');
|
|
if (!common.hasQuic)
|
|
common.skip('missing quic');
|
|
|
|
const path = require('path');
|
|
const { createQuicSocket } = require('net');
|
|
const { once } = require('events');
|
|
|
|
const { key, cert, ca } = require('../common/quic');
|
|
const options = { key, cert, ca, alpn: 'meow' };
|
|
|
|
const server = createQuicSocket({ server: options });
|
|
const client = createQuicSocket({ client: options });
|
|
|
|
(async function() {
|
|
server.on('session', common.mustCall(async (session) => {
|
|
const stream = await session.openStream({ halfOpen: true });
|
|
const nonexistentPath = path.resolve(__dirname, 'nonexistent.file');
|
|
stream.sendFile(nonexistentPath, {
|
|
onError: common.expectsError({
|
|
code: 'ENOENT',
|
|
syscall: 'open',
|
|
path: nonexistentPath
|
|
})
|
|
});
|
|
session.close();
|
|
|
|
session.on('close', common.mustCall());
|
|
}));
|
|
|
|
await server.listen();
|
|
|
|
const req = await client.connect({
|
|
address: 'localhost',
|
|
port: server.endpoints[0].address.port
|
|
});
|
|
|
|
req.on('stream', common.mustNotCall());
|
|
|
|
req.on('close', common.mustCall(() => {
|
|
client.close();
|
|
server.close();
|
|
}));
|
|
|
|
await Promise.all([
|
|
once(server, 'close'),
|
|
once(client, 'close')
|
|
]);
|
|
})().then(common.mustCall());
|