Skip to content

Commit 295b9a3

Browse files
committed
fix: properly handle failing handshakes
* Related #9 [ci skip]
1 parent 9b9c633 commit 295b9a3

File tree

5 files changed

+187
-138
lines changed

5 files changed

+187
-138
lines changed

src/QUICClient.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { QUICConfig } from './config';
44
import type QUICConnectionMap from './QUICConnectionMap';
55
import Logger from '@matrixai/logger';
66
import { CreateDestroy, ready } from '@matrixai/async-init/dist/CreateDestroy';
7-
import { running } from '@matrixai/async-init';
7+
import { destroyed, running } from '@matrixai/async-init';
88
import { quiche } from './native';
99
import * as utils from './utils';
1010
import * as errors from './errors';
@@ -162,22 +162,23 @@ class QUICClient extends EventTarget {
162162
// Console.error(e);
163163
logger.debug(`Is shared?: ${isSocketShared}`);
164164
// Waiting for connection to destroy
165-
const destroyedProm = utils.promise<void>();
166-
connection.addEventListener(
167-
'destroy',
168-
() => {
169-
destroyedProm.resolveP();
170-
},
171-
{
172-
once: true,
173-
},
174-
);
175-
await destroyedProm.p;
165+
if (connection[destroyed] === false) {
166+
const destroyedProm = utils.promise<void>();
167+
connection.addEventListener(
168+
'destroy',
169+
() => {
170+
destroyedProm.resolveP();
171+
},
172+
{
173+
once: true,
174+
},
175+
);
176+
await destroyedProm.p;
177+
}
176178
if (!isSocketShared) {
177179
// Stop our own socket
178180
await socket.stop();
179181
}
180-
// Wrapping error to contain both stack traces
181182
throw e;
182183
}
183184

0 commit comments

Comments
 (0)