From 51aef5f606776d6031ed0804b933c4e58a0740f0 Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Mon, 3 Jun 2024 16:30:04 +1000 Subject: [PATCH 1/2] fix: we now abort starting connection when stopping the `QUICServer` [ci skip] --- src/QUICServer.ts | 17 ++++++++++++++++- src/errors.ts | 5 +++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/QUICServer.ts b/src/QUICServer.ts index f6aeb154..48147058 100644 --- a/src/QUICServer.ts +++ b/src/QUICServer.ts @@ -10,6 +10,7 @@ import type { StreamReasonToCode, } from './types'; import type { Header } from './native/types'; +import nodesEvents from 'events'; import Logger from '@matrixai/logger'; import { AbstractEvent, EventAll } from '@matrixai/events'; import { @@ -62,6 +63,8 @@ class QUICServer { protected _closed: boolean = false; protected _closedP: Promise; protected resolveClosedP: () => void; + // Used to abort any starting connections when the server stops + protected stopAbortController: AbortController | undefined; /** * Handles `EventQUICServerError`. @@ -370,6 +373,10 @@ class QUICServer { reuseAddr?: boolean; ipv6Only?: boolean; } = {}) { + this.stopAbortController = new AbortController(); + // Since we have a one-to-many relationship with clients and connections, + // we want to up the warning limit on the stopAbortController + nodesEvents.setMaxListeners(100000, this.stopAbortController.signal); let address: string; if (!this.isSocketShared) { address = utils.buildAddress(host, port); @@ -444,6 +451,11 @@ class QUICServer { // Stop answering new connections this.socket.unsetServer(); const connectionsDestroyP: Array> = []; + // If force then signal for any starting connections to abort + if (force) { + this.stopAbortController?.abort(new errors.ErrorQUICServerStopping()); + } + this.stopAbortController = undefined; for (const connection of this.socket.connectionMap.serverConnections.values()) { connectionsDestroyP.push( connection.stop({ @@ -628,7 +640,10 @@ class QUICServer { data, remoteInfo, }, - { timer: this.minIdleTimeout }, + { + timer: this.minIdleTimeout, + signal: this.stopAbortController?.signal, + }, ); } catch (e) { connection.removeEventListener( diff --git a/src/errors.ts b/src/errors.ts index fd802643..1b8644d3 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -93,6 +93,10 @@ class ErrorQUICServerInternal extends ErrorQUICServer { static description = 'QUIC Server internal error'; } +class ErrorQUICServerStopping extends ErrorQUICServer { + static description = 'QUIC Server is stopping'; +} + class ErrorQUICConnection extends ErrorQUIC { static description = 'QUIC Connection error'; } @@ -306,6 +310,7 @@ export { ErrorQUICServerSocketNotRunning, ErrorQUICServerNewConnection, ErrorQUICServerInternal, + ErrorQUICServerStopping, ErrorQUICConnection, ErrorQUICConnectionStopping, ErrorQUICConnectionNotRunning, From 773855d6ec4b87f903780c9116354c69554fe8d6 Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Tue, 4 Jun 2024 16:09:58 +1000 Subject: [PATCH 2/2] 1.2.8 --- Cargo.lock | 2 +- Cargo.toml | 2 +- package-lock.json | 14 +++++++------- package.json | 12 ++++++------ 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bff5b9e4..47730477 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -391,7 +391,7 @@ dependencies = [ [[package]] name = "quic" -version = "1.2.7" +version = "1.2.8" dependencies = [ "boring", "napi", diff --git a/Cargo.toml b/Cargo.toml index ecb93db7..5f28886b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "quic" -version = "1.2.7" +version = "1.2.8" authors = ["Roger Qiu "] license-file = "LICENSE" edition = "2021" diff --git a/package-lock.json b/package-lock.json index 9fd14339..7e47c1f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@matrixai/quic", - "version": "1.2.7", + "version": "1.2.8", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@matrixai/quic", - "version": "1.2.7", + "version": "1.2.8", "license": "Apache-2.0", "dependencies": { "@matrixai/async-cancellable": "^1.1.1", @@ -57,11 +57,11 @@ "typescript": "^5.1.6" }, "optionalDependencies": { - "@matrixai/quic-darwin-arm64": "1.2.7", - "@matrixai/quic-darwin-universal": "1.2.7", - "@matrixai/quic-darwin-x64": "1.2.7", - "@matrixai/quic-linux-x64": "1.2.7", - "@matrixai/quic-win32-x64": "1.2.7" + "@matrixai/quic-darwin-arm64": "1.2.8", + "@matrixai/quic-darwin-universal": "1.2.8", + "@matrixai/quic-darwin-x64": "1.2.8", + "@matrixai/quic-linux-x64": "1.2.8", + "@matrixai/quic-win32-x64": "1.2.8" } }, "node_modules/@aashutoshrathi/word-wrap": { diff --git a/package.json b/package.json index ca4e8353..e8ee738c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@matrixai/quic", - "version": "1.2.7", + "version": "1.2.8", "author": "Matrix AI", "contributors": [ { @@ -48,11 +48,11 @@ "ip-num": "^1.5.0" }, "optionalDependencies": { - "@matrixai/quic-darwin-arm64": "1.2.7", - "@matrixai/quic-darwin-universal": "1.2.7", - "@matrixai/quic-darwin-x64": "1.2.7", - "@matrixai/quic-linux-x64": "1.2.7", - "@matrixai/quic-win32-x64": "1.2.7" + "@matrixai/quic-darwin-arm64": "1.2.8", + "@matrixai/quic-darwin-universal": "1.2.8", + "@matrixai/quic-darwin-x64": "1.2.8", + "@matrixai/quic-linux-x64": "1.2.8", + "@matrixai/quic-win32-x64": "1.2.8" }, "devDependencies": { "@fast-check/jest": "^1.1.0",