task runner: keepalive ping so long silent tasks don't get killed

a script task that goes silent for a while (e.g. ffmpeg's faststart pass rewrites
a huge file for minutes with no output) would hit Bun's default 120s websocket
idle timeout → close(ws) → killTree killed the task mid-run, corrupting the
output. now the executor pings the socket every 30s while a task runs, resetting
the idle timer.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-22 22:09:43 +00:00
co-authored by Claude Opus 4.8
parent a82ce9ecb0
commit 6ce75db150
+8
View File
@@ -235,6 +235,13 @@ async function handleRun(ws: ServerWebSocket<WSData>, msg: RunMessage) {
},
});
// Keep the WebSocket alive during long silent phases (e.g. ffmpeg's faststart pass rewrites a huge
// file for minutes with no output). Bun's default 120s idle timeout would otherwise close the
// socket → close(ws) → killTree kills the task mid-run. A ping resets the idle timer.
const keepAlive = setInterval(() => {
try { ws.ping(); } catch { /* socket gone */ }
}, 30_000);
const stdoutReader = proc.stdout.getReader();
const stderrReader = proc.stderr.getReader();
const decoder = new TextDecoder();
@@ -257,6 +264,7 @@ async function handleRun(ws: ServerWebSocket<WSData>, msg: RunMessage) {
proc.exited,
]);
clearInterval(keepAlive);
activeProcs.delete(ws);
cleanup();
send(ws, { type: 'exit', code: exitCode });