summaryrefslogtreecommitdiff
path: root/ext/http
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2024-06-14 06:38:50 +0530
committerGitHub <noreply@github.com>2024-06-14 06:38:50 +0530
commite19ee6eecc416a99801231ac53f2c512ba1f81dd (patch)
tree357c002418e444777c4f4189f216359cd4360bbb /ext/http
parent368eb9073bff776b8bb49480b98ca4628ebdc7cd (diff)
fix(ext/node): `server.close()` does graceful shutdown (#24184)
Diffstat (limited to 'ext/http')
-rw-r--r--ext/http/00_serve.ts48
1 files changed, 37 insertions, 11 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;