mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 11:50:42 +00:00
fix: guard all ws.send() calls with readyState check to prevent server crashes (#3936)
## Description: Several ws.send() calls in GameServer.ts were missing WebSocket.OPEN readyState guards. This can lead to server crashes if a client disconnects precisely between a check and the send. Added guards to prestart, kickClient, and handleSynchronization. ## 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 Co-authored-by: 22314621 <22314621@student.ciu.edu.tr>
This commit is contained in:
@@ -672,7 +672,9 @@ export class GameServer {
|
||||
clientID: c.clientID,
|
||||
persistentID: c.persistentID,
|
||||
});
|
||||
c.ws.send(msg);
|
||||
if (c.ws.readyState === WebSocket.OPEN) {
|
||||
c.ws.send(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -999,13 +1001,15 @@ export class GameServer {
|
||||
persistentID: client.persistentID,
|
||||
reasonKey,
|
||||
});
|
||||
client.ws.send(
|
||||
JSON.stringify({
|
||||
type: "error",
|
||||
error: reasonKey,
|
||||
} satisfies ServerErrorMessage),
|
||||
);
|
||||
client.ws.close(1000, reasonKey);
|
||||
if (client.ws.readyState === WebSocket.OPEN) {
|
||||
client.ws.send(
|
||||
JSON.stringify({
|
||||
type: "error",
|
||||
error: reasonKey,
|
||||
} satisfies ServerErrorMessage),
|
||||
);
|
||||
client.ws.close(1000, reasonKey);
|
||||
}
|
||||
this.activeClients = this.activeClients.filter(
|
||||
(c) => c.clientID !== clientID,
|
||||
);
|
||||
@@ -1137,7 +1141,9 @@ export class GameServer {
|
||||
clientID: c.clientID,
|
||||
persistentID: c.persistentID,
|
||||
});
|
||||
c.ws.send(desyncMsg);
|
||||
if (c.ws.readyState === WebSocket.OPEN) {
|
||||
c.ws.send(desyncMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user