summary refs log tree commit diff
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-01-26 14:29:33 +1100
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-01-26 14:29:33 +1100
commit45793e82fdbd21fcd91fe40576b37d076e3140a3 (patch)
treebdeb0f04b5a22e3f785f63f481f37b3e440e120c
parentDon't set default cdn endpoints. Null endpoints means to not update them in G... (diff)
downloadserver-45793e82fdbd21fcd91fe40576b37d076e3140a3.tar.xz
Fix SIGTERM handler not disconnecting gateway clients and leaving timeouts active
-rw-r--r--src/bundle/Server.ts3
-rw-r--r--src/gateway/Server.ts8
2 files changed, 9 insertions, 2 deletions
diff --git a/src/bundle/Server.ts b/src/bundle/Server.ts
index 96f6a149..119bb52b 100644
--- a/src/bundle/Server.ts
+++ b/src/bundle/Server.ts
@@ -39,6 +39,9 @@ const gateway = new Gateway.Server({ server, port, production });
 
 process.on("SIGTERM", async () => {
 	console.log("Shutting down due to SIGTERM");
+	await gateway.stop();
+	await cdn.stop();
+	await api.stop();
 	server.close();
 	Sentry.close();
 });
diff --git a/src/gateway/Server.ts b/src/gateway/Server.ts
index 81e4b7f4..3eec5c8f 100644
--- a/src/gateway/Server.ts
+++ b/src/gateway/Server.ts
@@ -82,7 +82,11 @@ export class Server {
 	}
 
 	async stop() {
-		closeDatabase();
-		this.server.close();
+		this.ws.clients.forEach((x) => x.close());
+		this.ws.close(() => {
+			this.server.close(() => {
+				closeDatabase();
+			});
+		});
 	}
 }