From c0889ba538034f4da23b98f2d123022be9ae24d6 Mon Sep 17 00:00:00 2001 From: evanpelle Date: Wed, 23 Jul 2025 16:35:11 -0700 Subject: [PATCH] Close websocket immediately after sending error. (#1551) ## Description: The delay was unnecessary and caused race conditions ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I have read and accepted the CLA aggreement (only required once). ## Please put your Discord username so you can be contacted if a bug or regression is found: evan --- src/server/GameServer.ts | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/server/GameServer.ts b/src/server/GameServer.ts index e8480e7d0..7832e8eb0 100644 --- a/src/server/GameServer.ts +++ b/src/server/GameServer.ts @@ -201,10 +201,7 @@ export class GameServer { message, } satisfies ServerErrorMessage), ); - // Add a small delay before closing the connection to ensure the error message is received - setTimeout(() => { - client.ws.close(1002, "ClientMessageSchema"); - }, 100); + client.ws.close(1002, "ClientMessageSchema"); return; } const clientMsg = parsed.data; @@ -551,15 +548,12 @@ export class GameServer { error: "Kicked from game (you may have been playing on another tab)", } satisfies ServerErrorMessage), ); - // Add a small delay before closing the connection to ensure the error message is received - setTimeout(() => { - client.ws.close(1000, "Kicked from game"); - this.activeClients = this.activeClients.filter( - (c) => c.clientID !== clientID, - ); - client.ws.removeAllListeners(); - this.kickedClients.add(clientID); - }, 100); + client.ws.close(1000, "Kicked from game"); + this.activeClients = this.activeClients.filter( + (c) => c.clientID !== clientID, + ); + client.ws.removeAllListeners(); + this.kickedClients.add(clientID); } else { this.log.warn(`cannot kick client, not found in game`, { clientID,