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
This commit is contained in:
Berk
2026-05-11 23:04:36 +03:00
committed by GitHub
parent 89d330cf64
commit 2b6ebbfe2d
+3 -1
View File
@@ -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);
}
});
}