From bf9b9a4b0dc208ca910a68fc14d987f2f326eba6 Mon Sep 17 00:00:00 2001 From: evanpelle Date: Mon, 9 Jun 2025 14:53:34 -0700 Subject: [PATCH] fix duplicate websocket handler (#1124) ## Description: Turns out ws.on adds a new listener, it doesn't remove the existing listener. so it turns out we had both worker & game server listening to messages. this only got noticed because we close web socket connection on parsing failure. ## 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 understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors ## Please put your Discord username so you can be contacted if a bug or regression is found: evan --- src/server/GameServer.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/server/GameServer.ts b/src/server/GameServer.ts index 88db909dd..57fced752 100644 --- a/src/server/GameServer.ts +++ b/src/server/GameServer.ts @@ -182,6 +182,7 @@ export class GameServer { this.allClients.set(client.clientID, client); + client.ws.removeAllListeners("message"); client.ws.on( "message", gatekeeper.wsHandler(client.ip, async (message: string) => { @@ -239,6 +240,7 @@ export class GameServer { } }), ); + client.ws.removeAllListeners("close"); client.ws.on("close", () => { this.log.info("client disconnected", { clientID: client.clientID, @@ -248,6 +250,7 @@ export class GameServer { (c) => c.clientID !== client.clientID, ); }); + client.ws.removeAllListeners("error"); client.ws.on("error", (error: Error) => { if ((error as any).code === "WS_ERR_UNEXPECTED_RSV_1") { client.ws.close(1002);