Skip to content

Commit

Permalink
quic: refactor/improve QuicSocket ready event handling
Browse files Browse the repository at this point in the history
PR-URL: #34247
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
jasnell committed Jul 9, 2020
1 parent e381326 commit afc9390
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/internal/quic/core.js
Expand Up @@ -1031,7 +1031,13 @@ class QuicSocket extends EventEmitter {
// used to either listen or connect. No QuicServerSession should
// exist before this event, and all QuicClientSession will remain
// in Initial states until ready is invoked.
process.nextTick(emit.bind(this, 'ready'));
process.nextTick(() => {
try {
this.emit('ready');
} catch (error) {
this.destroy(error);
}
});
}

// Called when a QuicEndpoint closes
Expand Down
31 changes: 31 additions & 0 deletions test/parallel/test-quic-server-ready-event-error-async.js
@@ -0,0 +1,31 @@
// Flags: --no-warnings
'use strict';

const common = require('../common');
if (!common.hasQuic)
common.skip('missing quic');

const assert = require('assert');
const {
key,
cert,
ca,
} = require('../common/quic');

const { createQuicSocket } = require('net');

const options = { key, cert, ca, alpn: 'zzz' };

const server = createQuicSocket({ server: options });

server.on('session', common.mustNotCall());

server.listen();

server.on('error', common.mustCall((error) => {
assert.strictEqual(error.message, 'boom');
}));

server.on('ready', common.mustCall(async () => {
throw new Error('boom');
}));
31 changes: 31 additions & 0 deletions test/parallel/test-quic-server-ready-event-error.js
@@ -0,0 +1,31 @@
// Flags: --no-warnings
'use strict';

const common = require('../common');
if (!common.hasQuic)
common.skip('missing quic');

const assert = require('assert');
const {
key,
cert,
ca,
} = require('../common/quic');

const { createQuicSocket } = require('net');

const options = { key, cert, ca, alpn: 'zzz' };

const server = createQuicSocket({ server: options });

server.on('session', common.mustNotCall());

server.listen();

server.on('error', common.mustCall((error) => {
assert.strictEqual(error.message, 'boom');
}));

server.on('ready', common.mustCall(() => {
throw new Error('boom');
}));

0 comments on commit afc9390

Please sign in to comment.