Skip to content

Commit 6b62491

Browse files
committed
fix: fixed edge cases leading to failures in ci
There were a few things here. For starters some of the new tests had some dumb config. A mistake on my part. The other part is that the `send` throws different errors depending on platform and context. I could only reasonably track it down based on testing in the CI... There are 3 main errors we're sending back to the connection to be dealt with.
1 parent 89de5f7 commit 6b62491

File tree

3 files changed

+35
-42
lines changed

3 files changed

+35
-42
lines changed

src/QUICClient.ts

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,25 @@ class QUICClient {
258258
evt: events.EventQUICClientErrorSend,
259259
) => {
260260
// @ts-ignore: the error contains `code` but not part of the type
261-
if (evt.detail.code === 'EINVAL') {
262-
abortController.abort(
263-
new errors.ErrorQUICClientInvalidArgument(undefined, {
264-
cause: evt.detail,
265-
}),
266-
);
261+
const code = evt.detail.code;
262+
switch (code) {
263+
// Thrown due to invalid arguments on linux
264+
case 'EINVAL':
265+
// Thrown due to invalid arguments on macOS
266+
// Falls through
267+
case 'EADDRNOTAVAIL':
268+
// Thrown due to invalid arguments on Win but also for network dropouts on all platforms
269+
// Falls through
270+
case 'ENETUNREACH':
271+
{
272+
abortController.abort(
273+
new errors.ErrorQUICClientInvalidArgument(undefined, {
274+
cause: evt.detail,
275+
}),
276+
);
277+
}
278+
break;
279+
default: // Do nothing
267280
}
268281
};
269282
client.addEventListener(
@@ -331,10 +344,6 @@ class QUICClient {
331344
protected config: Config;
332345
protected _closed: boolean = false;
333346
protected resolveClosedP: () => void;
334-
/**
335-
* Flag used to make sure network fail warnings are only logged once per failure
336-
*/
337-
protected networkWarned: boolean = false;
338347

339348
/**
340349
* Handles `EventQUICClientError`.
@@ -494,10 +503,16 @@ class QUICClient {
494503
evt.detail.port,
495504
evt.detail.address,
496505
);
497-
this.networkWarned = false;
498506
} catch (e) {
499507
switch (e.code) {
508+
// Thrown due to invalid arguments on linux
500509
case 'EINVAL':
510+
// Thrown due to invalid arguments on macOS
511+
// Falls through
512+
case 'EADDRNOTAVAIL':
513+
// Thrown due to invalid arguments on Win but also for network dropouts on all platforms
514+
// Falls through
515+
case 'ENETUNREACH':
501516
{
502517
this.dispatchEvent(
503518
new events.EventQUICClientErrorSend(
@@ -509,18 +524,6 @@ class QUICClient {
509524
);
510525
}
511526
break;
512-
case 'ENETUNREACH':
513-
{
514-
// We consider this branch a temp failure.
515-
// For these error codes we rely on the connection's timeout to handle.
516-
if (!this.networkWarned) {
517-
this.logger.warn(
518-
`client send failed with 'ENETUNREACH', likely due to network failure`,
519-
);
520-
this.networkWarned = true;
521-
}
522-
}
523-
break;
524527
default:
525528
{
526529
this.dispatchEvent(

src/QUICServer.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ class QUICServer {
6262
protected _closed: boolean = false;
6363
protected _closedP: Promise<void>;
6464
protected resolveClosedP: () => void;
65-
/**
66-
* Flag used to make sure network fail warnings are only logged once per failure
67-
*/
68-
protected networkWarned: boolean = false;
6965

7066
/**
7167
* Handles `EventQUICServerError`.
@@ -199,10 +195,16 @@ class QUICServer {
199195
evt.detail.port,
200196
evt.detail.address,
201197
);
202-
this.networkWarned = false;
203198
} catch (e) {
204199
switch (e.code) {
200+
// Thrown due to invalid arguments on linux
205201
case 'EINVAL':
202+
// Thrown due to invalid arguments on macOS
203+
// Falls through
204+
case 'EADDRNOTAVAIL':
205+
// Thrown due to invalid arguments on Win but also for network dropouts on all platforms
206+
// Falls through
207+
case 'ENETUNREACH':
206208
{
207209
this.dispatchEvent(
208210
new events.EventQUICClientErrorSend(
@@ -214,18 +216,6 @@ class QUICServer {
214216
);
215217
}
216218
break;
217-
case 'ENETUNREACH':
218-
{
219-
// We consider this branch a temp failure.
220-
// For these error codes we rely on the connection's timeout to handle.
221-
if (!this.networkWarned) {
222-
this.logger.warn(
223-
`server send failed with 'ENETUNREACH', likely due to network failure`,
224-
);
225-
this.networkWarned = true;
226-
}
227-
}
228-
break;
229219
default:
230220
{
231221
this.dispatchEvent(

tests/QUICStream.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,7 +1893,7 @@ describe(QUICStream.name, () => {
18931893
const client = await QUICClient.createQUICClient({
18941894
host: localhost,
18951895
port: server.port,
1896-
localHost: '192.168.56.1',
1896+
localHost: localhost,
18971897
crypto: {
18981898
ops: clientCrypto,
18991899
},
@@ -2025,7 +2025,7 @@ describe(QUICStream.name, () => {
20252025
const client = await QUICClient.createQUICClient({
20262026
host: localhost,
20272027
port: server.port,
2028-
localHost: '192.168.56.1',
2028+
localHost: localhost,
20292029
crypto: {
20302030
ops: clientCrypto,
20312031
},

0 commit comments

Comments
 (0)