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:
@@ -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 stdoutReader = proc.stdout.getReader();
|
||||||
const stderrReader = proc.stderr.getReader();
|
const stderrReader = proc.stderr.getReader();
|
||||||
const decoder = new TextDecoder();
|
const decoder = new TextDecoder();
|
||||||
@@ -257,6 +264,7 @@ async function handleRun(ws: ServerWebSocket<WSData>, msg: RunMessage) {
|
|||||||
proc.exited,
|
proc.exited,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
clearInterval(keepAlive);
|
||||||
activeProcs.delete(ws);
|
activeProcs.delete(ws);
|
||||||
cleanup();
|
cleanup();
|
||||||
send(ws, { type: 'exit', code: exitCode });
|
send(ws, { type: 'exit', code: exitCode });
|
||||||
|
|||||||
Reference in New Issue
Block a user