fix(boot): bound post-start health poll so a slow API cannot kill PM2 (BIT-32855) #296

Merged
spark merged 1 commits from fix/BIT-32855-bound-boot-health-wait into main 2026-11-22 01:24:01 +00:00
Owner

Why

boot.sh 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, 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.

Incident (BIT-32855)

HttpProbeFailed on http://10.10.50.63/ (pr_site, CT 266). Timeline:

  1. pr-api (CT 264) was vzmigrated to node obelix and rebooted.
  2. While pr-api was booting, pr-site's SSR fetch to API_URL=http://10.10.50.61:3000 failed -> Next.js returned 500.
  3. photoreport-boot.service wait_for (count-based, ~450s) exceeded TimeoutStartSec=300 (stale deployed unit) -> systemd killed the cgroup -> PM2 died -> nginx 502 -> blackbox probe failed.
  4. No self-heal: PM2 was gone, so even after pr-api came back (health 200), pr-site stayed 502.

Fix

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. On a clean exit the PM2 daemon survives (Type=oneshot, RemainAfterExit=yes).

Verification

  • bash -n infra/deploy/boot.sh (CI gate) passes.
  • Isolated wait_for unit tests: success path -> 0; budget timeout -> 1 within budget.
  • Live: pr-site probe from blackbox CT 224 -> 200; PM2 photoreport-site (2 instances) online, 0 restarts.

Operational follow-up (not in this PR)

The deployed photoreport-boot.service on CT 266 (and 265/267) is stale: TimeoutStartSec=300, no Restart=on-failure. The repo unit (infra/systemd/photoreport-boot.service) is already ahead (420 + Restart=on-failure/RestartSec=30/StartLimitBurst=5). Updating the unit on the CTs is a host-ops action (agents never SSH into containers, docs/DEPLOY.md) -- DevOps/sysadmin to install the repo unit + systemctl daemon-reload on each pr-* container.

Paperclip-Issue: BIT-32855

## Why `boot.sh` `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, `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. ## Incident (BIT-32855) `HttpProbeFailed` on `http://10.10.50.63/` (pr_site, CT 266). Timeline: 1. pr-api (CT 264) was `vzmigrate`d to node `obelix` and rebooted. 2. While pr-api was booting, pr-site's SSR fetch to `API_URL=http://10.10.50.61:3000` failed -> Next.js returned 500. 3. `photoreport-boot.service` `wait_for` (count-based, ~450s) exceeded `TimeoutStartSec=300` (stale deployed unit) -> systemd killed the cgroup -> PM2 died -> nginx 502 -> blackbox probe failed. 4. No self-heal: PM2 was gone, so even after pr-api came back (health 200), pr-site stayed 502. ## Fix 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. On a clean exit the PM2 daemon survives (`Type=oneshot`, `RemainAfterExit=yes`). ## Verification - `bash -n infra/deploy/boot.sh` (CI gate) passes. - Isolated `wait_for` unit tests: success path -> 0; budget timeout -> 1 within budget. - Live: pr-site probe from blackbox CT 224 -> `200`; PM2 `photoreport-site` (2 instances) `online`, 0 restarts. ## Operational follow-up (not in this PR) The deployed `photoreport-boot.service` on CT 266 (and 265/267) is stale: `TimeoutStartSec=300`, no `Restart=on-failure`. The repo unit (`infra/systemd/photoreport-boot.service`) is already ahead (`420` + `Restart=on-failure`/`RestartSec=30`/`StartLimitBurst=5`). Updating the unit on the CTs is a host-ops action (agents never SSH into containers, docs/DEPLOY.md) -- DevOps/sysadmin to install the repo unit + `systemctl daemon-reload` on each pr-* container. Paperclip-Issue: BIT-32855
spark added 1 commit 2026-11-22 01:14:37 +00:00
fix(boot): bound post-start health poll so a slow API cannot kill PM2 (BIT-32855)
ci / rust (pull_request) Successful in 4m29s
ci / typescript (pull_request) Successful in 9m10s
7813475a7c
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
spark merged commit 88e74d34ba into main 2026-11-22 01:24:01 +00:00
Sign in to join this conversation.