Skip to content

fix: rebind logging on HUP without breaking reopen - #3670

Open
alexchen-sys wants to merge 1 commit into
benoitc:masterfrom
alexchen-sys:fix/hup-reopen-error-log
Open

fix: rebind logging on HUP without breaking reopen#3670
alexchen-sys wants to merge 1 commit into
benoitc:masterfrom
alexchen-sys:fix/hup-reopen-error-log

Conversation

@alexchen-sys

@alexchen-sys alexchen-sys commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Fixes #3401.

After SIGHUP, new worker boot lines can vanish from the main error log even though the workers are healthy. The master reuses the same Logger instance on reload and only calls reopen_files(), which is not enough to rebind handlers to the reloaded config.

Reload now keeps logger.cfg aligned in Arbiter.setup() and re-runs Logger.setup(cfg) before reopen_files(). The setup is made idempotent: gunicorn-owned handlers are dropped before re-adding, a prior capture_output fd is closed, accesslog=None stays without handlers, and syslog is reattached without stacking.

reopen_files() keeps its USR1/logrotate meaning: it reopens existing FileHandlers only and no longer re-seeds default handlers over a logconfig configuration.

The regression tests cover the error-log path switch on reload and the logrotate-style reopen; a separate test checks that reopen does not re-seed default handlers over custom ones.

After SIGHUP, Gunicorn kept the Logger instance and only called
reopen_files(). That left stale handler state for --error-logfile and made
post-reload worker boot lines disappear from the main error log (benoitc#3401).

Changes:
- Arbiter.setup keeps logger.cfg aligned on reload
- Arbiter.reload calls Logger.setup(cfg) before reopen_files()
- Logger.setup is idempotent: drop all gunicorn-owned handlers, close prior
  capture_output FD, honor accesslog=None, reattach syslog cleanly
- reopen_files only reopens existing FileHandlers (USR1/logrotate) and does
  not re-seed default handlers over logconfig
- Regression tests for path switch, rotate, syslog stacking, accesslog
  disable, capture FD, and no re-seed over custom handlers

Signed-off-by: Alex Chen <l46983284@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gunicorn reload with HUP stops main logging

1 participant