Skip to content

Commit 63a54b0

Browse files
committed
not all children die equally
1 parent 903792f commit 63a54b0

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

docs/source/settings.rst

+4
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

+10-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ def __init__(self, app):
5959
self.pidfile = None
6060
self.systemd = False
6161
self.worker_age = 0
62+
# old master has != 0 until new master is dead or promoted
6263
self.reexec_pid = 0
64+
# new master has != 0 until old master is dead (until promotion)
6365
self.master_pid = 0
6466
self.master_name = "Master"
6567

@@ -411,8 +413,10 @@ def reexec(self):
411413
master_pid = os.getpid()
412414
self.reexec_pid = os.fork()
413415
if self.reexec_pid != 0:
416+
# old master
414417
return
415418

419+
# new master
416420
self.cfg.pre_exec(self)
417421

418422
environ = self.cfg.env_orig.copy()
@@ -517,7 +521,13 @@ def reap_workers(self):
517521
break
518522
if self.reexec_pid == wpid:
519523
self.reexec_pid = 0
524+
self.log.info("Master exited before promotion.")
525+
continue
520526
else:
527+
worker = self.WORKERS.pop(wpid, None)
528+
if not worker:
529+
self.log.debug("Non-worker subprocess (pid:%s) exited", wpid)
530+
continue
521531
# A worker was terminated. If the termination reason was
522532
# that it could not boot, we'll shut it down to avoid
523533
# infinite start/stop cycles.
@@ -552,9 +562,6 @@ def reap_workers(self):
552562
msg += " Perhaps out of memory?"
553563
self.log.error(msg)
554564

555-
worker = self.WORKERS.pop(wpid, None)
556-
if not worker:
557-
continue
558565
worker.tmp.close()
559566
self.cfg.child_exit(self, worker)
560567
except OSError as e:

gunicorn/config.py

+4
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)