fix(api): various subtle memory leaks

(and some not so subtle ones, *cough* ReportService *cough*)
This commit is contained in:
Hampus Kraft
2026-02-27 04:50:21 +00:00
parent 848269a4d4
commit 7b1aa6ff2e
8 changed files with 193 additions and 41 deletions

View File

@@ -34,6 +34,7 @@ export class VoiceTopology {
private subscribers: Set<Subscriber> = new Set();
private serverRotationIndex: Map<string, number> = new Map();
private kvSubscription: IKVSubscription | null = null;
private messageHandler: ((channel: string) => void) | null = null;
constructor(
private voiceRepository: IVoiceRepository,
@@ -53,13 +54,14 @@ export class VoiceTopology {
this.kvSubscription = subscription;
await subscription.connect();
await subscription.subscribe(VOICE_CONFIGURATION_CHANNEL);
subscription.on('message', (channel) => {
this.messageHandler = (channel: string) => {
if (channel === VOICE_CONFIGURATION_CHANNEL) {
this.reload().catch((error) => {
Logger.error({error}, 'Failed to reload voice topology from KV notification');
});
}
});
};
subscription.on('message', this.messageHandler);
} catch (error) {
Logger.error({error}, 'Failed to subscribe to voice configuration channel');
}
@@ -239,9 +241,13 @@ export class VoiceTopology {
}
shutdown(): void {
if (this.kvSubscription && this.messageHandler) {
this.kvSubscription.removeAllListeners('message');
}
if (this.kvSubscription) {
this.kvSubscription.disconnect();
this.kvSubscription = null;
}
this.messageHandler = null;
}
}