fix(voice-call): use iterative queue processing to prevent heap exhaustion

The recursive processQueue() pattern accumulated stack frames, causing
JavaScript heap out of memory errors on macOS CI. Convert to while loop
for constant stack usage regardless of queue depth.
This commit is contained in:
Dan Guido 2026-01-25 02:22:55 -05:00 committed by Peter Steinberger
parent 76014685eb
commit 1005934964

View File

@ -252,21 +252,24 @@ export class MediaStreamHandler {
/**
* Process the TTS queue for a stream.
* Uses iterative approach to avoid stack accumulation from recursion.
*/
private async processQueue(streamSid: string): Promise<void> {
const queue = this.ttsQueues.get(streamSid);
if (!queue || queue.length === 0) {
this.ttsPlaying.set(streamSid, false);
return;
}
this.ttsPlaying.set(streamSid, true);
const playFn = queue.shift()!;
try {
await playFn();
} finally {
await this.processQueue(streamSid);
while (true) {
const queue = this.ttsQueues.get(streamSid);
if (!queue || queue.length === 0) {
this.ttsPlaying.set(streamSid, false);
return;
}
const playFn = queue.shift()!;
try {
await playFn();
} catch (error) {
console.error("[MediaStream] TTS playback error:", error);
}
}
}