mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-18 16:12:41 +00:00
fix server memory leak (#1524)
## Description: After v24 release, the server had has a bad memory leak, causing worker memory to rise to 1gb after ~12 hours. I believed this is caused by not removing listeners on websocket when kicking a client. ## 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:
@@ -183,9 +183,7 @@ export class GameServer {
|
||||
|
||||
this.allClients.set(client.clientID, client);
|
||||
|
||||
client.ws.removeAllListeners("message");
|
||||
client.ws.removeAllListeners("close");
|
||||
client.ws.removeAllListeners("error");
|
||||
client.ws.removeAllListeners();
|
||||
client.ws.on(
|
||||
"message",
|
||||
gatekeeper.wsHandler(client.ip, async (message: string) => {
|
||||
@@ -405,7 +403,7 @@ export class GameServer {
|
||||
// Close all WebSocket connections
|
||||
clearInterval(this.endTurnIntervalID);
|
||||
this.allClients.forEach((client) => {
|
||||
client.ws.removeAllListeners("message");
|
||||
client.ws.removeAllListeners();
|
||||
if (client.ws.readyState === WebSocket.OPEN) {
|
||||
client.ws.close(1000, "game has ended");
|
||||
}
|
||||
@@ -559,6 +557,7 @@ export class GameServer {
|
||||
this.activeClients = this.activeClients.filter(
|
||||
(c) => c.clientID !== clientID,
|
||||
);
|
||||
client.ws.removeAllListeners();
|
||||
this.kickedClients.add(clientID);
|
||||
}, 100);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user