From ce36d3f0fb3c490aef71657c8609ae33d07960e4 Mon Sep 17 00:00:00 2001 From: zurdi Date: Wed, 23 Sep 2026 21:14:34 +0200 Subject: [PATCH] review: guard the RQ worker PID file and comment it where it is written Adds a test that start_rq_worker records $! instead of passing --pid, and moves the comment next to the line it explains. Co-Authored-By: Claude Opus 5.5 --- backend/tests/test_web_server_config.py | 13 +++++++++++++ docker/init_scripts/init | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/backend/tests/test_web_server_config.py b/backend/tests/test_web_server_config.py index 59c2c2d1d..323c28024 100644 --- a/backend/tests/test_web_server_config.py +++ b/backend/tests/test_web_server_config.py @@ -82,6 +82,19 @@ def test_gunicorn_outlives_nginx_upstream_idle_timeout() -> None: assert _init_script_keepalive() > NGINX_UPSTREAM_IDLE_TIMEOUT +def test_init_script_records_the_rq_worker_pid_at_launch() -> None: + match = re.search( + r"^start_rq_worker\(\) \{\n(.*?)^\}", INIT_SCRIPT.read_text(), re.M | re.S + ) + assert match, "could not read start_rq_worker from the init script" + body = match.group(1) + assert not re.search(r"^\s*--pid\b", body, re.M), ( + "RQ writes --pid only after importing the worker class, so the watchdog " + "would start duplicate workers while a slow import runs" + ) + assert re.search(r'^\s*echo "\$!" >"/tmp/\$\{name\}\.pid"$', body, re.M) + + def test_env_template_documents_the_same_keepalive_default() -> None: match = re.search(r"^WEB_SERVER_KEEPALIVE=(\d+)", ENV_TEMPLATE.read_text(), re.M) assert match, "env.template is missing WEB_SERVER_KEEPALIVE" diff --git a/docker/init_scripts/init b/docker/init_scripts/init index a2643f334..4c9f080ba 100755 --- a/docker/init_scripts/init +++ b/docker/init_scripts/init @@ -278,8 +278,6 @@ start_bin_rq_scan_worker() { # orphaned STARTED jobs and stale workers are still pruned promptly. # --with-scheduler releases delayed jobs, which is how the watcher's rescans # wait out their delay. -# The PID is recorded here, not with --pid: RQ writes that file only after -# importing the worker class, and the watchdog would start a duplicate meanwhile. start_rq_worker() { local name="$1" shift @@ -296,6 +294,8 @@ start_rq_worker() { --logging_level "${LOGLEVEL}" \ --with-scheduler \ "$@" & + # Not --pid: RQ writes that file only once the worker class is imported, + # and until then the watchdog would start a duplicate. echo "$!" >"/tmp/${name}.pid" }