From e19ee6eecc416a99801231ac53f2c512ba1f81dd Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Fri, 14 Jun 2024 06:38:50 +0530 Subject: fix(ext/node): `server.close()` does graceful shutdown (#24184) --- ext/node/polyfills/http.ts | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'ext/node/polyfills') 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, -- cgit v1.2.3