From 2b6ebbfe2d5661f0eacca358bc589d5a4f9ffc0f Mon Sep 17 00:00:00 2001 From: Berk Date: Mon, 11 May 2026 23:04:36 +0300 Subject: [PATCH] fix: add readyState check before endTurn broadcast (#3879) ## Description: Guard `ws.send()` in `endTurn()` with a `readyState === OPEN` check to prevent sending messages to WebSocket connections that have already closed. Without this guard, broadcasting to a client whose connection closed between ticks can throw an exception and crash the game loop. ## 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 ## Please put your Discord username so you can be contacted if a bug or regression is found: barfires --- src/server/GameServer.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/server/GameServer.ts b/src/server/GameServer.ts index e2213de07..a19327f9d 100644 --- a/src/server/GameServer.ts +++ b/src/server/GameServer.ts @@ -823,7 +823,9 @@ export class GameServer { turn: pastTurn, } satisfies ServerTurnMessage); this.activeClients.forEach((c) => { - c.ws.send(msg); + if (c.ws.readyState === c.ws.OPEN) { + c.ws.send(msg); + } }); }