fix(voice-call): clamp pre-start stream timeout

This commit is contained in:
Peter Steinberger
2026-05-30 16:32:39 -04:00
parent 1ff52b2786
commit e500f401ea
2 changed files with 30 additions and 1 deletions
@@ -1,5 +1,6 @@
import type { IncomingMessage } from "node:http";
import net from "node:net";
import { MAX_TIMER_TIMEOUT_MS } from "openclaw/plugin-sdk/number-runtime";
import type {
RealtimeTranscriptionProviderPlugin,
RealtimeTranscriptionSession,
@@ -435,6 +436,30 @@ describe("MediaStreamHandler security hardening", () => {
}
});
it("clamps oversized pre-start connection timeouts", () => {
vi.useFakeTimers();
try {
const handler = new MediaStreamHandler({
transcriptionProvider: createStubSttProvider(),
providerConfig: {},
preStartTimeoutMs: Number.MAX_SAFE_INTEGER,
});
const setTimeoutSpy = vi.spyOn(globalThis, "setTimeout");
const ws = { close: vi.fn() } as unknown as WebSocket;
const registered = (
handler as unknown as {
registerPendingConnection(ws: WebSocket, ip: string): boolean;
}
).registerPendingConnection(ws, "203.0.113.10");
expect(registered).toBe(true);
expect(setTimeoutSpy).toHaveBeenCalledWith(expect.any(Function), MAX_TIMER_TIMEOUT_MS);
} finally {
vi.useRealTimers();
}
});
it("enforces pending connection limits", async () => {
const handler = new MediaStreamHandler({
transcriptionProvider: createStubSttProvider(),
+5 -1
View File
@@ -10,6 +10,7 @@
import type { IncomingMessage } from "node:http";
import type { Duplex } from "node:stream";
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
import { resolveTimerTimeoutMs } from "openclaw/plugin-sdk/number-runtime";
import type {
RealtimeTranscriptionProviderConfig,
RealtimeTranscriptionProviderPlugin,
@@ -155,7 +156,10 @@ export class MediaStreamHandler {
constructor(config: MediaStreamConfig) {
this.config = config;
this.preStartTimeoutMs = config.preStartTimeoutMs ?? DEFAULT_PRE_START_TIMEOUT_MS;
this.preStartTimeoutMs = resolveTimerTimeoutMs(
config.preStartTimeoutMs,
DEFAULT_PRE_START_TIMEOUT_MS,
);
this.maxPendingConnections = config.maxPendingConnections ?? DEFAULT_MAX_PENDING_CONNECTIONS;
this.maxPendingConnectionsPerIp =
config.maxPendingConnectionsPerIp ?? DEFAULT_MAX_PENDING_CONNECTIONS_PER_IP;