remove all ws listeners (#1498)

## Description:

v24 introduced a memory leak in the worker. It may be caused by
improperly cleaning up websockets.

## 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-19 09:35:13 -07:00
committed by GitHub
parent 13f94ed36e
commit 4dda53b564
+9
View File
@@ -316,6 +316,7 @@ export function startWorker() {
error: error.toString(),
} satisfies ServerErrorMessage),
);
ws.removeAllListeners();
ws.close(1002, "ClientJoinMessageSchema");
return;
}
@@ -333,6 +334,7 @@ export function startWorker() {
error,
} satisfies ServerErrorMessage),
);
ws.removeAllListeners();
ws.close(1002, "ClientJoinMessageSchema");
return;
}
@@ -350,6 +352,7 @@ export function startWorker() {
const result = await verifyClientToken(clientMsg.token, config);
if (result === false) {
log.warn("Unauthorized: Invalid token");
ws.removeAllListeners();
ws.close(1002, "Unauthorized");
return;
}
@@ -362,6 +365,7 @@ export function startWorker() {
if (claims === null) {
if (allowedFlares !== undefined) {
log.warn("Unauthorized: Anonymous user attempted to join game");
ws.removeAllListeners();
ws.close(1002, "Unauthorized");
return;
}
@@ -370,6 +374,7 @@ export function startWorker() {
const result = await getUserMe(clientMsg.token, config);
if (result === false) {
log.warn("Unauthorized: Invalid session");
ws.removeAllListeners();
ws.close(1002, "Unauthorized");
return;
}
@@ -384,6 +389,7 @@ export function startWorker() {
log.warn(
"Forbidden: player without an allowed flare attempted to join game",
);
ws.removeAllListeners();
ws.close(1002, "Forbidden");
return;
}
@@ -400,6 +406,7 @@ export function startWorker() {
);
if (allowed !== true) {
log.warn(`Custom flag ${allowed}: ${clientMsg.flag}`);
ws.removeAllListeners();
ws.close(1002, `Custom flag ${allowed}`);
return;
}
@@ -415,6 +422,7 @@ export function startWorker() {
);
if (allowed !== true) {
log.warn(`Pattern ${allowed}: ${clientMsg.pattern}`);
ws.removeAllListeners();
ws.close(1002, `Pattern ${allowed}`);
return;
}
@@ -460,6 +468,7 @@ export function startWorker() {
);
ws.on("error", (error: Error) => {
ws.removeAllListeners();
if ((error as any).code === "WS_ERR_UNEXPECTED_RSV_1") {
ws.close(1002, "WS_ERR_UNEXPECTED_RSV_1");
}