mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-11 23:00:03 +00:00
fix(encoder): signal host interruptions for retry (#3578)
* fix(encoder): signal host interruptions for retry * fix(encoder): cover all render interruption paths * fix(encoder): classify HDR pre-extraction drains
This commit is contained in:
@@ -23,12 +23,32 @@ export interface RunFfmpegOptions {
|
||||
export interface RunFfmpegResult {
|
||||
success: boolean;
|
||||
exitCode: number | null;
|
||||
signal?: NodeJS.Signals | null;
|
||||
stderr: string;
|
||||
durationMs: number;
|
||||
terminationReason: ManagedProcessTerminationReason;
|
||||
failureReason?: "external_interruption";
|
||||
error?: Error;
|
||||
}
|
||||
|
||||
const FFMPEG_SIGTERM_EXIT_LINE = /^Exiting normally, received signal 15\.?\r?$/m;
|
||||
|
||||
/**
|
||||
* Return true only when ffmpeg was terminated from outside this managed call.
|
||||
*
|
||||
* FFmpeg handles SIGTERM itself and can therefore report exit code 255 with a
|
||||
* null Node signal. The exact terminal stderr line covers that case. Managed
|
||||
* abort/deadline/inactivity reasons always take precedence so our own SIGTERM
|
||||
* requests never become retryable lifecycle interruptions.
|
||||
*/
|
||||
export function isExternalFfmpegInterruption(
|
||||
result: Pick<RunFfmpegResult, "exitCode" | "signal" | "stderr" | "terminationReason">,
|
||||
): boolean {
|
||||
if (result.terminationReason !== "exit" || result.exitCode === 0) return false;
|
||||
if (result.signal === "SIGTERM") return true;
|
||||
return result.exitCode === 255 && FFMPEG_SIGTERM_EXIT_LINE.test(result.stderr);
|
||||
}
|
||||
|
||||
const DEFAULT_TIMEOUT = 300_000;
|
||||
|
||||
const DEFAULT_STDERR_TAIL_LINES = 15;
|
||||
@@ -104,12 +124,17 @@ export async function runFfmpeg(args: string[], opts?: RunFfmpegOptions): Promis
|
||||
onStderr: opts?.onStderr,
|
||||
});
|
||||
const outcome = await managed.wait();
|
||||
return {
|
||||
const result: RunFfmpegResult = {
|
||||
success: outcome.reason === "exit" && outcome.exitCode === 0,
|
||||
exitCode: outcome.exitCode,
|
||||
signal: outcome.signal,
|
||||
stderr: outcome.stderr,
|
||||
durationMs: outcome.durationMs,
|
||||
terminationReason: outcome.reason,
|
||||
error: outcome.error,
|
||||
};
|
||||
if (isExternalFfmpegInterruption(result)) {
|
||||
result.failureReason = "external_interruption";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user