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
This commit is contained in:
evanpelle
2025-07-23 16:35:11 -07:00
committed by GitHub
parent ff17d321c7
commit c0889ba538
+7 -13
View File
@@ -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,