fix: rebind logging on HUP without breaking reopen - #3670
Open
alexchen-sys wants to merge 1 commit into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Loggerinstance on reload and only callsreopen_files(), which is not enough to rebind handlers to the reloaded config.Reload now keeps
logger.cfgaligned inArbiter.setup()and re-runsLogger.setup(cfg)beforereopen_files(). The setup is made idempotent: gunicorn-owned handlers are dropped before re-adding, a priorcapture_outputfd is closed,accesslog=Nonestays without handlers, and syslog is reattached without stacking.reopen_files()keeps its USR1/logrotate meaning: it reopens existingFileHandlers only and no longer re-seeds default handlers over alogconfigconfiguration.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.