mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-23 14:45:46 +00:00
fix(voice-call): clear connection timeout on successful STT connect (#58586)
The 10-second connection timeout in OpenAIRealtimeSTTSession.doConnect() was never cleared on success or teardown, leaking a timer on every connection and accumulating stale timers across reconnect cycles. Store the timeout handle and clear it in both the open handler and close(), matching the existing clearTimeout pattern in waitForTranscript(). Co-authored-by: Sharoon Sharif <ssharif@Hosanna.local> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -89,6 +89,7 @@ class OpenAIRealtimeSTTSession implements RealtimeSTTSession {
|
||||
private ws: WebSocket | null = null;
|
||||
private connected = false;
|
||||
private closed = false;
|
||||
private connectTimeout: ReturnType<typeof setTimeout> | null = null;
|
||||
private reconnectAttempts = 0;
|
||||
private pendingTranscript = "";
|
||||
private onTranscriptCallback: ((transcript: string) => void) | null = null;
|
||||
@@ -123,6 +124,10 @@ class OpenAIRealtimeSTTSession implements RealtimeSTTSession {
|
||||
console.log("[RealtimeSTT] WebSocket connected");
|
||||
this.connected = true;
|
||||
this.reconnectAttempts = 0;
|
||||
if (this.connectTimeout) {
|
||||
clearTimeout(this.connectTimeout);
|
||||
this.connectTimeout = null;
|
||||
}
|
||||
|
||||
// Configure the transcription session
|
||||
this.sendEvent({
|
||||
@@ -172,7 +177,8 @@ class OpenAIRealtimeSTTSession implements RealtimeSTTSession {
|
||||
}
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
this.connectTimeout = setTimeout(() => {
|
||||
this.connectTimeout = null;
|
||||
if (!this.connected) {
|
||||
reject(new Error("Realtime STT connection timeout"));
|
||||
}
|
||||
@@ -298,6 +304,10 @@ class OpenAIRealtimeSTTSession implements RealtimeSTTSession {
|
||||
|
||||
close(): void {
|
||||
this.closed = true;
|
||||
if (this.connectTimeout) {
|
||||
clearTimeout(this.connectTimeout);
|
||||
this.connectTimeout = null;
|
||||
}
|
||||
if (this.ws) {
|
||||
this.ws.close();
|
||||
this.ws = null;
|
||||
|
||||
Reference in New Issue
Block a user