Skip to content

Commit e8b1d8a

Browse files
authored
Merge pull request #88 from MatrixAI/revert-86-feature-socket-errors
Revert "Gracefully handle certain `QUICSocket.send` errors"
2 parents 31df593 + 800c5cc commit e8b1d8a

File tree

6 files changed

+17
-405
lines changed

6 files changed

+17
-405
lines changed

src/QUICClient.ts

Lines changed: 9 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -247,34 +247,8 @@ class QUICClient {
247247
// the client, because the client bridges the push flow from the connection
248248
// to the socket.
249249
socket.connectionMap.set(connection.connectionId, connection);
250-
// Set up intermediate abort signal
251-
const abortController = new AbortController();
252-
const abortHandler = () => {
253-
abortController.abort(ctx.signal.reason);
254-
};
255-
if (ctx.signal.aborted) abortController.abort(ctx.signal.reason);
256-
else ctx.signal.addEventListener('abort', abortHandler);
257-
const handleEventQUICClientErrorSend = (
258-
evt: events.EventQUICClientErrorSend,
259-
) => {
260-
// @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-
);
267-
}
268-
};
269-
client.addEventListener(
270-
`${events.EventQUICClientErrorSend.name}-${connection.sendId}`,
271-
handleEventQUICClientErrorSend,
272-
);
273250
try {
274-
await connection.start(undefined, {
275-
timer: ctx.timer,
276-
signal: abortController.signal,
277-
});
251+
await connection.start(undefined, ctx);
278252
} catch (e) {
279253
socket.connectionMap.delete(connection.connectionId);
280254
socket.removeEventListener(
@@ -310,12 +284,6 @@ class QUICClient {
310284
client.handleEventQUICClientClose,
311285
);
312286
throw e;
313-
} finally {
314-
ctx.signal.removeEventListener('abort', abortHandler);
315-
client.removeEventListener(
316-
`${events.EventQUICClientErrorSend.name}-${connection.sendId}`,
317-
handleEventQUICClientErrorSend,
318-
);
319287
}
320288
address = utils.buildAddress(host_, port);
321289
logger.info(`Created ${this.name} to ${address}`);
@@ -331,10 +299,6 @@ class QUICClient {
331299
protected config: Config;
332300
protected _closed: boolean = false;
333301
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;
338302

339303
/**
340304
* Handles `EventQUICClientError`.
@@ -494,49 +458,15 @@ class QUICClient {
494458
evt.detail.port,
495459
evt.detail.address,
496460
);
497-
this.networkWarned = false;
498461
} catch (e) {
499-
switch (e.code) {
500-
case 'EINVAL':
501-
{
502-
this.dispatchEvent(
503-
new events.EventQUICClientErrorSend(
504-
`${events.EventQUICClientErrorSend.name}-${evt.detail.id}`,
505-
{
506-
detail: e,
507-
},
508-
),
509-
);
510-
}
511-
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;
524-
default:
525-
{
526-
this.dispatchEvent(
527-
new events.EventQUICClientError({
528-
detail: new errors.ErrorQUICClientInternal(
529-
'Failed to send data on the QUICSocket',
530-
{
531-
data: evt.detail,
532-
cause: e,
533-
},
534-
),
535-
}),
536-
);
537-
}
538-
break;
539-
}
462+
const e_ = new errors.ErrorQUICClientInternal(
463+
'Failed to send data on the QUICSocket',
464+
{
465+
data: evt.detail,
466+
cause: e,
467+
},
468+
);
469+
this.dispatchEvent(new events.EventQUICClientError({ detail: e_ }));
540470
}
541471
};
542472

src/QUICConnection.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ class QUICConnection {
6262
*/
6363
public readonly streamMap: Map<StreamId, QUICStream> = new Map();
6464

65-
/**
66-
* Unique id used to identify events intended for this connection.
67-
*/
68-
public readonly sendId: string;
69-
7065
protected logger: Logger;
7166
protected socket: QUICSocket;
7267
protected config: QUICConfig;
@@ -327,7 +322,6 @@ class QUICConnection {
327322
logger?: Logger;
328323
}) {
329324
this.logger = logger ?? new Logger(`${this.constructor.name} ${scid}`);
330-
this.sendId = scid.toString();
331325
if (
332326
config.keepAliveIntervalTime != null &&
333327
config.maxIdleTimeout !== 0 &&
@@ -882,7 +876,6 @@ class QUICConnection {
882876
this.dispatchEvent(
883877
new events.EventQUICConnectionSend({
884878
detail: {
885-
id: this.sendId,
886879
msg: sendBuffer.subarray(0, sendLength),
887880
port: sendInfo.to.port,
888881
address: sendInfo.to.host,

src/QUICServer.ts

Lines changed: 8 additions & 46 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,49 +195,15 @@ class QUICServer {
199195
evt.detail.port,
200196
evt.detail.address,
201197
);
202-
this.networkWarned = false;
203198
} catch (e) {
204-
switch (e.code) {
205-
case 'EINVAL':
206-
{
207-
this.dispatchEvent(
208-
new events.EventQUICClientErrorSend(
209-
`${events.EventQUICClientErrorSend.name}-${evt.detail.id}`,
210-
{
211-
detail: e,
212-
},
213-
),
214-
);
215-
}
216-
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;
229-
default:
230-
{
231-
this.dispatchEvent(
232-
new events.EventQUICServerError({
233-
detail: new errors.ErrorQUICServerInternal(
234-
'Failed to send data on the QUICSocket',
235-
{
236-
data: evt.detail,
237-
cause: e,
238-
},
239-
),
240-
}),
241-
);
242-
}
243-
break;
244-
}
199+
const e_ = new errors.ErrorQUICServerInternal(
200+
'Failed to send data on the QUICSocket',
201+
{
202+
data: evt.detail,
203+
cause: e,
204+
},
205+
);
206+
this.dispatchEvent(new events.EventQUICServerError({ detail: e_ }));
245207
}
246208
};
247209

src/errors.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ class ErrorQUICClientSocketNotRunning<T> extends ErrorQUICClient<T> {
5959
'QUIC Client cannot be created with an unstarted shared QUIC socket';
6060
}
6161

62-
class ErrorQUICClientInvalidArgument<T> extends ErrorQUICClient<T> {
63-
static description =
64-
'QUIC Client had a failure relating to an invalid argument';
65-
}
66-
6762
class ErrorQUICClientInvalidHost<T> extends ErrorQUICClient<T> {
6863
static description = 'QUIC Client cannot be created with the specified host';
6964
}
@@ -298,7 +293,6 @@ export {
298293
ErrorQUICClientDestroyed,
299294
ErrorQUICClientCreateTimeout,
300295
ErrorQUICClientSocketNotRunning,
301-
ErrorQUICClientInvalidArgument,
302296
ErrorQUICClientInvalidHost,
303297
ErrorQUICClientInternal,
304298
ErrorQUICServer,

src/events.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ class EventQUICClientError extends EventQUICClient<
6262
| ErrorQUICConnectionInternal<unknown>
6363
> {}
6464

65-
class EventQUICClientErrorSend extends EventQUICSocket<Error> {}
66-
6765
class EventQUICClientClose extends EventQUICClient<
6866
| ErrorQUICClientSocketNotRunning<unknown>
6967
| ErrorQUICConnectionLocal<unknown>
@@ -128,7 +126,6 @@ class EventQUICConnectionClose extends EventQUICConnection<
128126
class EventQUICConnectionStream extends EventQUICConnection<QUICStream> {}
129127

130128
class EventQUICConnectionSend extends EventQUICConnection<{
131-
id: string;
132129
msg: Uint8Array;
133130
port: number;
134131
address: string;
@@ -196,7 +193,6 @@ export {
196193
EventQUICClientDestroy,
197194
EventQUICClientDestroyed,
198195
EventQUICClientError,
199-
EventQUICClientErrorSend,
200196
EventQUICClientClose,
201197
EventQUICServer,
202198
EventQUICServerStart,

0 commit comments

Comments
 (0)