Skip to content

Commit

Permalink
arbiter: don't log if handling SIGCHLD
Browse files Browse the repository at this point in the history
Logging when handling a signal is a bad practice
See https://docs.python.org/3/library/logging.html#thread-safety

Fixes benoitc#2816
  • Loading branch information
hydrargyrum authored Sep 5, 2023
1 parent ab9c830 commit 5286a10
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions gunicorn/arbiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def run(self):

def handle_chld(self, sig, frame):
"SIGCHLD handling"
self.reap_workers()
self.reap_workers(signal_safe=False)
self.wakeup()

def handle_hup(self):
Expand Down Expand Up @@ -507,7 +507,7 @@ def murder_workers(self):
else:
self.kill_worker(pid, signal.SIGKILL)

def reap_workers(self):
def reap_workers(self, signal_safe=True):
"""\
Reap workers to avoid zombie processes
"""
Expand All @@ -532,12 +532,12 @@ def reap_workers(self):
reason = "App failed to load."
raise HaltServer(reason, self.APP_LOAD_ERROR)

if exitcode > 0:
if signal_safe and exitcode > 0:
# If the exit code of the worker is greater than 0,
# let the user know.
self.log.error("Worker (pid:%s) exited with code %s.",
wpid, exitcode)
elif status > 0:
elif signal_safe and status > 0:
# If the exit code of the worker is 0 and the status
# is greater than 0, then it was most likely killed
# via a signal.
Expand Down

0 comments on commit 5286a10

Please sign in to comment.