fix(cd-infra): don't SIGHUP a Prometheus that compose just started #24
No reviewers
Labels
No labels
dependencies
major
security-pin
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
trails-cool/trails!24
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/cd-infra-prometheus-sighup-race"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes #23. One-line guard plus the reasoning that makes it obvious in six months.
What happened
cd-infrarun #94 started Prometheus and killed it one second later, taking metrics and alert evaluation down for ~16 minutes:Why
The config-reload branch gated on container identity alone:
The intent is right — Prometheus mounts its config directory, so a replaced config is visible live and SIGHUP applies it without recreating the container. The flaw is that
docker inspectanswers for a stopped container too, verified on the flagship with a throwaway container:.Id.State.Running9f7f1020e584false9f7f1020e584false6fac3fb66adatrueSo a Prometheus that entered the deploy stopped got started by
up -dunder the same ID, the IDs matched, and the branch fired ~1s into WAL replay — before Prometheus installs its SIGHUP handler, and SIGHUP's default disposition is terminate.ID equality was standing in for "was already running". Those diverge in exactly one state: stopped-but-present. Which is also the state where the reload is least necessary, since a just-started process already loaded the new config.
The fix
Truth table across all five reachable states, old logic vs new:
up -dup -dOnly the failing row changes. The reload path this branch exists for is untouched.
Verification
.State.Runningsemantics confirmed against real Docker on the flagship (table above); probe container removedbash -non the deploy script extracted from the YAML block scalar — the\line continuations survive extraction intactNot in scope
#23's open question stands. Something SIGTERMed Prometheus at 11:55:07 and recreated five containers around 11:53, both before run #94's SSH step began at 12:04:27 — that earlier partial execution is what created the stopped-but-present state this fix now handles safely.
concurrency: cancel-in-progress: trueondeploy-infrais the obvious suspect. This PR makes the consequence harmless; it does not explain the cause, so I've left #23 open for it.Also left alone: the readiness gate. It behaved correctly — refusing to report success is why this was a noisy 16-minute outage instead of a silent one.
Note on verifying this
This changes
.forgejo/workflows/cd-infra.yml, which is not matched by cd-infra's ownpaths: ["infrastructure/**"]filter — so merging will not trigger a deploy, andmainkeeps run #94's red status until something does. Aworkflow_dispatchafter merge would both confirm green and exercise the intended HUP path (Prometheus is running now, soBEFORE_RUNNING=trueand the reload happens as designed).