From 7813475a7cc8a3b46872e4ab2a2ce5570610ae8f Mon Sep 17 00:00:00 2001 From: paula-alves Date: Sun, 22 Nov 2026 01:13:58 +0000 Subject: [PATCH] fix(boot): bound post-start health poll so a slow API cannot kill PM2 (BIT-32855) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit wait_for polled on a fixed try count (HEALTH_TRIES=90, ~450s worst case), which exceeded photoreport-boot.service's TimeoutStartSec. When the API a container depends on was briefly down (pr-api rebooting after a vzmigrate), pr-site's wait_for never got 200, systemd timed the oneshot out, killed the whole cgroup — including the PM2 daemon boot.sh had just launched — and left nginx with no upstream (502) that never self-healed even after the API recovered. Bound wait_for by wall clock (BOOT_HEALTH_BUDGET_SEC, default 150s) so boot.sh always exits within TimeoutStartSec with margin for the pm2_start retry path. PM2 (autorestart) and the next-env watchdog handle real recovery; this poll only confirms the boot. Paperclip-Issue: BIT-32855 --- infra/deploy/boot.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/infra/deploy/boot.sh b/infra/deploy/boot.sh index 22b32f7..78fa2f1 100755 --- a/infra/deploy/boot.sh +++ b/infra/deploy/boot.sh @@ -12,7 +12,14 @@ unset PORT DEPLOY_WEBHOOK_SECRET DEPLOY_SERVICE DEPLOY_SCRIPT DEPLOY_LOG REPO_DIR="${DEPLOY_REPO_DIR:-/srv/photoreport}" API_PORT="${API_PORT:-3000}" SITE_PORT="${SITE_PORT:-3100}" -HEALTH_TRIES="${BOOT_HEALTH_TRIES:-90}" +# Bound the post-start health poll by wall-clock, not by a try count. A count of 90 (sleep 2 + +# max-time 3) could run ~450s and exceed photoreport-boot.service's TimeoutStartSec, at which +# point systemd kills the whole cgroup — including the PM2 daemon this script just launched — +# and leaves the port closed with no self-heal (BIT-32855: pr-site turned a transient pr-api +# reboot into a persistent 502 this way). PM2 (autorestart) and the next-env watchdog handle +# real recovery; this poll only confirms the boot, so a 150s budget fits under both the +# deployed 300s and the repo's 420s TimeoutStartSec with margin for the pm2_start retry path. +HEALTH_BUDGET_SEC="${BOOT_HEALTH_BUDGET_SEC:-150}" log() { printf '[%s] boot %s: %s\n' "$(date -u +%FT%TZ)" "$SERVICE" "$*"; } @@ -31,8 +38,8 @@ cd "$REPO_DIR" SHA="$(git rev-parse HEAD)" wait_for() { - local url="$1" i - for ((i = 1; i <= HEALTH_TRIES; i++)); do + local url="$1" start=$SECONDS + while (( SECONDS - start < HEALTH_BUDGET_SEC )); do curl -fsS --max-time 3 -o /dev/null "$url" 2>/dev/null && return 0 sleep 2 done -- 2.47.3