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