Skip to content

Commit d4540ce

Browse files
committed
proc management: not all children die equally
1 parent 56b5ad8 commit d4540ce

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

docs/source/settings.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,10 @@ A filename to use for the PID file.
11001100

11011101
If not set, no PID file will be written.
11021102

1103+
.. note::
1104+
During master re-exec, a ``.2`` suffix is added to
1105+
this path to store the PID of the newly launched master.
1106+
11031107
.. _worker-tmp-dir:
11041108

11051109
``worker_tmp_dir``

gunicorn/arbiter.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ def __init__(self, app):
6060
self.pidfile = None
6161
self.systemd = False
6262
self.worker_age = 0
63+
# old master has != 0 until new master is dead or promoted
6364
self.reexec_pid = 0
65+
# new master has != 0 until old master is dead (until promotion)
6466
self.master_pid = 0
6567
self.master_name = "Master"
6668

@@ -413,8 +415,10 @@ def reexec(self):
413415
master_pid = os.getpid()
414416
self.reexec_pid = os.fork()
415417
if self.reexec_pid != 0:
418+
# old master
416419
return
417420

421+
# new master
418422
self.cfg.pre_exec(self)
419423

420424
environ = self.cfg.env_orig.copy()
@@ -519,7 +523,13 @@ def reap_workers(self):
519523
break
520524
if self.reexec_pid == wpid:
521525
self.reexec_pid = 0
526+
self.log.info("Master exited before promotion.")
527+
continue
522528
else:
529+
worker = self.WORKERS.pop(wpid, None)
530+
if not worker:
531+
self.log.debug("Non-worker subprocess (pid:%s) exited", wpid)
532+
continue
523533
# A worker was terminated. If the termination reason was
524534
# that it could not boot, we'll shut it down to avoid
525535
# infinite start/stop cycles.
@@ -554,9 +564,6 @@ def reap_workers(self):
554564
msg += " Perhaps out of memory?"
555565
self.log.error(msg)
556566

557-
worker = self.WORKERS.pop(wpid, None)
558-
if not worker:
559-
continue
560567
worker.tmp.close()
561568
self.cfg.child_exit(self, worker)
562569
except OSError as e:

gunicorn/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,10 @@ class Pidfile(Setting):
11231123
A filename to use for the PID file.
11241124
11251125
If not set, no PID file will be written.
1126+
1127+
.. note::
1128+
During master re-exec, a ``.2`` suffix is added to
1129+
this path to store the PID of the newly launched master.
11261130
"""
11271131

11281132

0 commit comments

Comments
 (0)