Sitelet https://web.archive.org/web/20211206003845/https://github.com/nodejs/node/commit/9f552df5b4
Skip to content
Permalink
Browse files
quic: fix endpointClose error handling, document
PR-URL: #34283
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
jasnell committed Jul 16, 2020
1 parent b80108c commit 9f552df5b4892530e3c8cabc31705b265c317304
Showing with 24 additions and 2 deletions.
  1. +15 −0 doc/api/quic.md
  2. +7 −2 lib/internal/quic/core.js
  3. +2 −0 test/parallel/test-quic-client-server.js
@@ -1354,6 +1354,21 @@ Emitted after the `QuicSocket` has been destroyed and is no longer usable.

The `'close'` event will not be emitted multiple times.

#### Event: `'endpointClose'`
<!-- YAML
added: REPLACEME
-->

Emitted after a `QuicEndpoint` associated witht the `QuicSocket` closes and
has been destroyed. The handler will be invoked with two arguments:

* `endpoint` {QuicEndpoint} The `QuicEndpoint` that has been destroyed.
* `error` {Error} An `Error` object if the `QuicEndpoint` was destroyed because
of an error.

When all of the `QuicEndpoint` instances associated with a `QuicSocket` have
closed, the `QuicEndpoint` will also automatically close.

#### Event: `'error'`
<!-- YAML
added: REPLACEME
@@ -1056,12 +1056,17 @@ class QuicSocket extends EventEmitter {
[kEndpointClose](endpoint, error) {
const state = this[kInternalState];
state.endpoints.delete(endpoint);
process.nextTick(emit.bind(this, 'endpointClose', endpoint, error));
process.nextTick(() => {
try {
this.emit('endpointClose', endpoint, error);
} catch (error) {
this.destroy(error);
}
});

// If there are no more QuicEndpoints, the QuicSocket is no
// longer usable.
if (state.endpoints.size === 0) {
// Ensure that there are absolutely no additional sessions
for (const session of state.sessions)
session.destroy(error);

@@ -222,6 +222,8 @@ server.on('ready', common.mustCall(() => {
client = createQuicSocket({ client: { key, cert, ca, alpn: kALPN }
});

client.on('endpointClose', common.mustCall());

client.on('close', common.mustCall(() => {
debug('Client closing. Duration', client.duration);
debug(' Bound duration',

0 comments on commit 9f552df

Please sign in to comment.