Skip to content

Commit afc9390

Browse files
committed
quic: refactor/improve QuicSocket ready event handling
PR-URL: #34247 Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent e381326 commit afc9390

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

lib/internal/quic/core.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,13 @@ class QuicSocket extends EventEmitter {
10311031
// used to either listen or connect. No QuicServerSession should
10321032
// exist before this event, and all QuicClientSession will remain
10331033
// in Initial states until ready is invoked.
1034-
process.nextTick(emit.bind(this, 'ready'));
1034+
process.nextTick(() => {
1035+
try {
1036+
this.emit('ready');
1037+
} catch (error) {
1038+
this.destroy(error);
1039+
}
1040+
});
10351041
}
10361042

10371043
// Called when a QuicEndpoint closes
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Flags: --no-warnings
2+
'use strict';
3+
4+
const common = require('../common');
5+
if (!common.hasQuic)
6+
common.skip('missing quic');
7+
8+
const assert = require('assert');
9+
const {
10+
key,
11+
cert,
12+
ca,
13+
} = require('../common/quic');
14+
15+
const { createQuicSocket } = require('net');
16+
17+
const options = { key, cert, ca, alpn: 'zzz' };
18+
19+
const server = createQuicSocket({ server: options });
20+
21+
server.on('session', common.mustNotCall());
22+
23+
server.listen();
24+
25+
server.on('error', common.mustCall((error) => {
26+
assert.strictEqual(error.message, 'boom');
27+
}));
28+
29+
server.on('ready', common.mustCall(async () => {
30+
throw new Error('boom');
31+
}));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Flags: --no-warnings
2+
'use strict';
3+
4+
const common = require('../common');
5+
if (!common.hasQuic)
6+
common.skip('missing quic');
7+
8+
const assert = require('assert');
9+
const {
10+
key,
11+
cert,
12+
ca,
13+
} = require('../common/quic');
14+
15+
const { createQuicSocket } = require('net');
16+
17+
const options = { key, cert, ca, alpn: 'zzz' };
18+
19+
const server = createQuicSocket({ server: options });
20+
21+
server.on('session', common.mustNotCall());
22+
23+
server.listen();
24+
25+
server.on('error', common.mustCall((error) => {
26+
assert.strictEqual(error.message, 'boom');
27+
}));
28+
29+
server.on('ready', common.mustCall(() => {
30+
throw new Error('boom');
31+
}));

0 commit comments

Comments
 (0)