Skip to content

Commit 80f8317

Browse files
liangweifengclaude
andcommitted
fix: close WebSocket after commit timeout in both realtime sessions
WebSocket adversarial scenario audit found: when commit() times out (30s), the Promise was resolved but the WebSocket left open. This wastes server resources and could cause stale events from being processed by a future session. Fixed in both OpenAIRealtimeSession and ParaformerRealtimeSession: timeout callbacks now call this.close() after resolving. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ce13df5 commit 80f8317

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

electron/stt-service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class OpenAIRealtimeSession implements IRealtimeSession {
230230
this.finishedResolve = resolve;
231231
if (this.config.finishEvent) this.ws!.send(JSON.stringify(this.config.finishEvent));
232232
this.commitTimeout = setTimeout(() => {
233-
if (this.finishedResolve) { this.finishedResolve = null; resolve(this.getFinalText()); }
233+
if (this.finishedResolve) { this.finishedResolve = null; resolve(this.getFinalText()); this.close(); }
234234
}, 30000);
235235
});
236236
}
@@ -239,7 +239,7 @@ class OpenAIRealtimeSession implements IRealtimeSession {
239239
this.completeResolve = resolve;
240240
if (this.config.commitEvent) this.ws!.send(JSON.stringify(this.config.commitEvent));
241241
this.commitTimeout = setTimeout(() => {
242-
if (this.completeResolve) { this.completeResolve = null; resolve(this.getFinalText()); }
242+
if (this.completeResolve) { this.completeResolve = null; resolve(this.getFinalText()); this.close(); }
243243
}, 30000);
244244
});
245245
}
@@ -434,6 +434,7 @@ class ParaformerRealtimeSession implements IRealtimeSession {
434434
console.warn('[Paraformer] finish timeout');
435435
this.finishedResolve = null;
436436
resolve(this.getFinalText());
437+
this.close();
437438
}
438439
}, 30000);
439440
});

0 commit comments

Comments
 (0)