Skip to content

Commit 4eb0b3f

Browse files
jasnellcjihrig
authored andcommitted
quic: fix endpointClose error handling, document
PR-URL: #34283 Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent b9297f3 commit 4eb0b3f

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

doc/api/quic.md

+15
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,21 @@ Emitted after the `QuicSocket` has been destroyed and is no longer usable.
13541354

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

1357+
#### Event: `'endpointClose'`
1358+
<!-- YAML
1359+
added: REPLACEME
1360+
-->
1361+
1362+
Emitted after a `QuicEndpoint` associated witht the `QuicSocket` closes and
1363+
has been destroyed. The handler will be invoked with two arguments:
1364+
1365+
* `endpoint` {QuicEndpoint} The `QuicEndpoint` that has been destroyed.
1366+
* `error` {Error} An `Error` object if the `QuicEndpoint` was destroyed because
1367+
of an error.
1368+
1369+
When all of the `QuicEndpoint` instances associated with a `QuicSocket` have
1370+
closed, the `QuicEndpoint` will also automatically close.
1371+
13571372
#### Event: `'error'`
13581373
<!-- YAML
13591374
added: REPLACEME

lib/internal/quic/core.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1056,12 +1056,17 @@ class QuicSocket extends EventEmitter {
10561056
[kEndpointClose](endpoint, error) {
10571057
const state = this[kInternalState];
10581058
state.endpoints.delete(endpoint);
1059-
process.nextTick(emit.bind(this, 'endpointClose', endpoint, error));
1059+
process.nextTick(() => {
1060+
try {
1061+
this.emit('endpointClose', endpoint, error);
1062+
} catch (error) {
1063+
this.destroy(error);
1064+
}
1065+
});
10601066

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

test/parallel/test-quic-client-server.js

+2
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ server.on('ready', common.mustCall(() => {
222222
client = createQuicSocket({ client: { key, cert, ca, alpn: kALPN }
223223
});
224224

225+
client.on('endpointClose', common.mustCall());
226+
225227
client.on('close', common.mustCall(() => {
226228
debug('Client closing. Duration', client.duration);
227229
debug(' Bound duration',

0 commit comments

Comments
 (0)