From acca967a4a96d83269cb1b37ca2506be2a3c4d84 Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Sat, 15 Jan 2022 23:57:56 +0700 Subject: [PATCH] improve timeout logic --- src/ffmpeg.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/ffmpeg.js b/src/ffmpeg.js index 1a8f7d55..dda6935d 100644 --- a/src/ffmpeg.js +++ b/src/ffmpeg.js @@ -38,9 +38,11 @@ export async function runFfprobe(args, { timeout = isDev ? 10000 : 30000 } = {}) console.warn('killing timed out ffprobe'); ps.kill(); }, timeout); - const ret = await ps; - clearTimeout(timer); - return ret; + try { + return await ps; + } finally { + clearTimeout(timer); + } } export function runFfmpeg(args) { @@ -487,8 +489,13 @@ export async function renderWaveformPng({ filePath, aroundTime, window, color }) ps1.kill(); ps2.kill(); }, 10000); - const { stdout } = await ps2; - clearTimeout(timer); + + let stdout; + try { + ({ stdout } = await ps2); + } finally { + clearTimeout(timer); + } const blob = new Blob([stdout], { type: 'image/png' });