From 2599a376af9953b84cc957643e5c86691b787bca Mon Sep 17 00:00:00 2001 From: Flag Date: Wed, 22 Apr 2026 09:35:48 +0000 Subject: [PATCH] =?UTF-8?q?dispatcher=20=C2=97=20fix=20race=20condition=20?= =?UTF-8?q?sur=20exit=5Ffile=20extract?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Le setsid bash lance ffmpeg puis ecrit le code de retour: echo $? > exit_file Avec test -f on matchait le fichier pendant que le shell le creait vide (write() du "> exit_file" cree le fichier avant fwrite). Resultat: code_str="" -> isdigit()=False -> rc=1 -> ffmpeg failed false positive. Fix: test -s (existe ET non-vide) pour attendre que echo ait termine. --- scripts/dispatcher.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/dispatcher.py b/scripts/dispatcher.py index f740c46..c42e3c2 100644 --- a/scripts/dispatcher.py +++ b/scripts/dispatcher.py @@ -209,7 +209,9 @@ def do_extract(job: sqlite3.Row, worker: dict) -> str: ssh(worker["ssh_alias"], f"setsid bash -c {shlex.quote(bg)} >/dev/null 2>&1 &") while True: - rc_done, _, _ = ssh(worker["ssh_alias"], f"test -f {shlex.quote(exit_file)}") + # Use -s (file exists AND size > 0) to avoid race: setsid bash writes the exit code + # AFTER ffmpeg finishes; a plain -f can match a zero-byte placeholder mid-write. + rc_done, _, _ = ssh(worker["ssh_alias"], f"test -s {shlex.quote(exit_file)}") current = count_frames(worker, frames_dir) pct = min(99, current * 100 // total_frames_est) set_status(job["id"], frame_count=current, progress=pct)