fix(nginx): reload via SIGHUP instead of starting a second master#68
fix(nginx): reload via SIGHUP instead of starting a second master#68omarsy wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 639c6db8e5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| nginx | ||
| fi | ||
| done No newline at end of file | ||
| inotifywait --exclude '\.crl$' -e create -e modify -e delete -e move /root/ |
There was a problem hiding this comment.
Keep watching until both cert files are written
When _install_cert copies /root/pem.crt and then /root/cert.key as separate Docker writes (app/workers/register.py), this now wakes on the .crt event. inotifywait --help confirms that without --monitor it exits after one received event, so the script stops watching while nginx -t runs; if the key write lands in that window, that event is lost and nginx returns without starting/reloading until some unrelated later /root change. This makes initial cert install or renewal racy; add a debounce/quiet-period or otherwise wait for the cert/key pair before testing/reloading.
Useful? React with 👍 / 👎.
639c6db to
8057225
Compare
Deep-review pass — applied hardeningReviewed adversarially against busybox/ash and the alpine image. Confirmed: Hardening applied since the first push:
Known, accepted for this hotfix (follow-up): nginx still daemonizes, so PID 1 is this script and a master crash is only recovered via the 60s poll, not a container restart. Restructuring to a foreground master is out of scope here.
|
8057225 to
b8f216a
Compare
nginx.sh "reloaded" by running bare `nginx`, which starts a second
master that cannot bind 0.0.0.0:443 ("Address in use") and exits. So
after the first start, no cert or config change ever took effect: cert
rotations were silently dropped until a full container restart, and the
manager's periodic CRL copy into /root triggered a failed-reload storm
every sync interval (incident 2026-06-13).
Use `nginx -s reload` (keeps the listening sockets, re-execs workers)
when a master is already running, and `nginx` only to start one. Start
once up front so a container restart with certs already on disk brings
nginx up without waiting for an event, and exclude *.crl from the watch
since this nginx never references the CRL.
Watch in --monitor mode so no event is lost: the manager installs the
cert as three separate writes, and a one-shot inotifywait could exit on
the .crt event and miss the .key write while `nginx -t` runs, leaving
nginx un-(re)loaded until an unrelated later change. An outer loop
respawns the watch if it dies. Surface `nginx -t` failures when the cert
is present instead of silently doing nothing.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
b8f216a to
a18e10b
Compare
|
@codex thanks, addressed in Switched the watch to |
|
To use Codex here, create an environment for this repo. |
Incident
Greffer nginx logged a reload storm, ~every 300s (the CRL sync interval):
Root cause
nginx/nginx.sh"reloaded" by running barenginx, which starts a second master that cannot bind 443 (the running master holds it), errorsAddress in use, and exits. Two consequences:nginx.sh-driven reload ever took effect, so a rotated cert was never picked up until a full container restart. A latent outage: the day a greffer cert expires before a restart, the manager edge starts rejecting it./root/revoked.crltripped the watch every sync interval, producing the failed-reload storm. (This nginx never references the CRL: nossl_crlinnginx.conf.)The running master kept serving throughout, so this was not itself the user-facing 502 (that was the manager edge, see greffon/manager#101). But it was masking a real reliability bug.
Fix
nginx -s reload(SIGHUP: keeps listening sockets, re-execs workers) when a master is already running; usenginxonly to start one.*.crlfrom the watch, since this nginx never loads the CRL. That also silences the storm regardless of chore: remove dead CRL-to-nginx sync (nginx never loads the file) #54.Testing
sh -n nginx/nginx.shpasses. Logic reviewed againstpidof nginx/nginx -tsemantics.Reloading Nginx Configuration+ successful SIGHUP (noAddress in use), and CRL writes no longer trigger reloads.Relation to #54
Independent of #54 (remove dead CRL sync) and complementary: this makes the reload mechanism correct; #54 removes the dead CRL copy that was tripping it. Note #54's deploy ordering constraint called out in greffon/manager#101.
🤖 Generated with Claude Code