opus-transcriber-proxy: OpenAIBackend error handler recurses into close(), crashing the process (issues disabled on that repo)
Filing here because jitsi/opus-transcriber-proxy has issues disabled.
A failing upstream STT connection takes down the entire proxy process with
RangeError: Maximum call stack size exceeded, killing every in-flight transcription
session rather than just the one that failed.
Cause
src/backends/OpenAIBackend.ts — the error listener (line 74) calls this.close():
ws.addEventListener('error', (event) => {
...
this.status = 'failed';
this.close(); // line 74
reject(new Error(`WebSocket error: ${errorMessage}`));
});and close() (line 146) is:
close(): void {
logger.debug(`Closing OpenAI backend for tag: ${this.tag}`);
this.ws?.close(); // <-- undici dispatches 'error' synchronously here
this.ws = undefined; // <-- never reached on the recursive path
this.status = 'closed';
}When the socket is still CONNECTING, undici fails the connection inside ws.close()
and dispatches another error event synchronously — before this.ws = undefined
runs. So the intended guard never takes effect and the handler re-enters until the
stack is exhausted.
Reproduction
Point openai_custom at a server that completes the HTTP handshake but does not
negotiate the realtime subprotocol. Per RFC 6455 undici must then fail the
connection, which triggers the loop every time.
[ERROR] OpenAI WebSocket error for tag b41ee7ee-a0: Connection was closed before it was established.
... identical line ~2000 times, ~1ms apart ...
RangeError: Maximum call stack size exceeded
at fireEvent (node:internal/deps/undici/undici:12006:14)
at failWebsocketConnection (node:internal/deps/undici/undici:12087:9)
at closeWebSocketConnection (node:internal/deps/undici/undici:12362:9)
at WebSocket.close (node:internal/deps/undici/undici:13117:9)
at OpenAIBackend.close (dist/bundle/server.js:1630:14)
at WebSocket.<anonymous> (dist/bundle/server.js:1568:16)Node v22.23.2, image jitsi/opus-transcriber-proxy:latest (gitHash 4d56863).
Why this is worth fixing beyond the crash
While the proxy restarts, JVB cannot connect and logs
Failed to upgrade to websocket: Unexpected HTTP Response Status Code: 400 Bad Request
Scheduling reconnection attempt N in 30000 msThe 400 is misleading — the proxy is simply down at that moment. I spent a while
auditing my jicofo.transcription.url-template before realising the backend was in a
crash loop. Anyone debugging a custom endpoint will likely take the same detour.
Suggested fix
Clear the reference before closing, so the synchronous re-entry is a no-op:
close(): void {
const ws = this.ws;
this.ws = undefined;
this.status = 'closed';
ws?.close();
}An explicit re-entry guard in the error handler (if (this.status === 'failed') return;)
would also work. The same error → close() shape appears in the other backends, so
they may share the issue.
Context
Found while building a local-ASR adapter behind openai_custom
(https://github.com/LeonardNJU/jitsi-local-asr) — running Paraformer/SenseVoice ONNX
on-box instead of a cloud STT. Happy to open a PR against opus-transcriber-proxy if
that is the preferred route.
Source: jitsi/jitsi-meet