From b924a2ffe5b806c0fc6fcbcbe602a560d3296bd8 Mon Sep 17 00:00:00 2001 From: Rory& Date: Tue, 26 May 2026 10:23:42 +0200 Subject: [PATCH] Gateway: send reconnect on shutdown --- src/gateway/events/Connection.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/gateway/events/Connection.ts b/src/gateway/events/Connection.ts index 5876c3e15..6f67c0c59 100644 --- a/src/gateway/events/Connection.ts +++ b/src/gateway/events/Connection.ts @@ -43,6 +43,17 @@ export async function Connection(this: WS.Server, socket: WebSocket, request: In if (index !== -1) openConnections.splice(index, 1); }); + for (const sig of ["SIGINT", "SIGTERM", "SIGQUIT"] as const) { + process.on(sig, async () => { + await Send(socket, { + op: OPCODES.Reconnect, + s: socket.sequence++, + d: Math.round(Math.random() * 5000), + }); + socket.close(1000); + }); + } + const forwardedFor = Config.get().security.forwardedFor; const ipAddress = forwardedFor ? (request.headers[forwardedFor.toLowerCase()] as string) : request.socket.remoteAddress;