fix redis listener leak in StreamingApiServerService.ts

This commit is contained in:
Hazelnoot 2025-06-25 22:51:16 -04:00
parent 4e609478f8
commit 168a364162

View file

@ -201,10 +201,12 @@ export class StreamingApiServerService {
const globalEv = new EventEmitter();
this.redisForSub.on('message', (_: string, data: string) => {
const onRedis = (_: string, data: string) => {
const parsed = JSON.parse(data);
globalEv.emit('message', parsed);
});
};
this.redisForSub.on('message', onRedis);
this.#wss.on('connection', async (connection: WebSocket.WebSocket, request: http.IncomingMessage, ctx: {
stream: MainStreamConnection,
@ -235,6 +237,7 @@ export class StreamingApiServerService {
connection.once('close', () => {
ev.removeAllListeners();
stream.dispose();
this.redisForSub.off('message', onRedis);
globalEv.off('message', onRedisMessage);
this.#connections.delete(connection);
if (userUpdateIntervalId) clearInterval(userUpdateIntervalId);