Fix setproctitle initialization with systemd socket activation (#3465)

Force early setproctitle initialization by calling getproctitle()
immediately after import. This ensures setproctitle captures the
argv/environ memory layout before systemd.listen_fds() modifies
the environment by removing LISTEN_FDS and LISTEN_PID.

Without this fix, if LISTEN_FDS is the first environment variable,
setproctitle fails to detect argv correctly and silently fails.

Fixes #3430
This commit is contained in:
Benoit Chesneau 2026-01-25 15:18:04 +01:00 committed by GitHub
parent 29830ccc2f
commit bbae34b951
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -53,7 +53,12 @@ if sys.platform == "darwin":
pass
else:
try:
from setproctitle import setproctitle
from setproctitle import setproctitle, getproctitle
# Force early initialization before any os.environ modifications
# (e.g. removing LISTEN_FDS in systemd socket activation)
# https://github.com/benoitc/gunicorn/issues/3430
getproctitle()
def _setproctitle(title):
setproctitle("gunicorn: %s" % title)