diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/http/00_serve.ts | 48 | ||||
-rw-r--r-- | ext/node/polyfills/http.ts | 28 |
2 files changed, 63 insertions, 13 deletions
diff --git a/ext/http/00_serve.ts b/ext/http/00_serve.ts index 7c665ac15..84b8cd321 100644 --- a/ext/http/00_serve.ts +++ b/ext/http/00_serve.ts @@ -753,26 +753,52 @@ function serveHttpOn(context, addr, callback) { PromisePrototypeCatch(callback(req), promiseErrorHandler); } - if (!context.closing && !context.closed) { - context.closing = op_http_close(rid, false); + try { + if (!context.closing && !context.closed) { + context.closing = await op_http_close(rid, false); + context.close(); + } + + await context.closing; + } catch (error) { + if (ObjectPrototypeIsPrototypeOf(InterruptedPrototype, error)) { + return; + } + if (ObjectPrototypeIsPrototypeOf(BadResourcePrototype, error)) { + return; + } + + throw error; + } finally { context.close(); + context.closed = true; } - - await context.closing; - context.close(); - context.closed = true; })(); return { addr, finished, async shutdown() { - if (!context.closing && !context.closed) { - // Shut this HTTP server down gracefully - context.closing = op_http_close(context.serverRid, true); + try { + if (!context.closing && !context.closed) { + // Shut this HTTP server down gracefully + context.closing = op_http_close(context.serverRid, true); + } + + await context.closing; + } catch (error) { + // The server was interrupted + if (ObjectPrototypeIsPrototypeOf(InterruptedPrototype, error)) { + return; + } + if (ObjectPrototypeIsPrototypeOf(BadResourcePrototype, error)) { + return; + } + + throw error; + } finally { + context.closed = true; } - await context.closing; - context.closed = true; }, ref() { ref = true; diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts index 32e69772d..c6c112a50 100644 --- a/ext/node/polyfills/http.ts +++ b/ext/node/polyfills/http.ts @@ -1775,8 +1775,12 @@ export class ServerImpl extends EventEmitter { } if (listening && this.#ac) { - this.#ac.abort(); - this.#ac = undefined; + if (this.#server) { + this.#server.shutdown(); + } else if (this.#ac) { + this.#ac.abort(); + this.#ac = undefined; + } } else { this.#serveDeferred!.resolve(); } @@ -1785,6 +1789,26 @@ export class ServerImpl extends EventEmitter { return this; } + closeAllConnections() { + if (this.#hasClosed) { + return; + } + if (this.#ac) { + this.#ac.abort(); + this.#ac = undefined; + } + } + + closeIdleConnections() { + if (this.#hasClosed) { + return; + } + + if (this.#server) { + this.#server.shutdown(); + } + } + address() { return { port: this.#addr.port, |