Skip to content

Commit

Permalink
Re-add the warning for workers terminated due to a signal
Browse files Browse the repository at this point in the history
Original: b695b49 (benoitc#2475)
Reverted: 76f8da2

The warnings are printed later in the main loop, not directly in the signal
handler. This should fix the RuntimeError from benoitc#2564.
  • Loading branch information
TomiBelan committed Dec 20, 2022
1 parent 008d81d commit 01cf842
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions gunicorn/arbiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def __init__(self, app):
self.master_pid = 0
self.master_name = "Master"

self.signal_warnings = []

cwd = util.getcwd()

args = sys.argv[:]
Expand Down Expand Up @@ -204,6 +206,14 @@ def run(self):
while True:
self.maybe_promote_master()

warnings, self.signal_warnings = self.signal_warnings, []
for (wpid, sig) in warnings:
self.log.warning(
"Worker with pid %s was terminated due to signal %s",
wpid,
sig,
)

sig = self.SIG_QUEUE.pop(0) if self.SIG_QUEUE else None
if sig is None:
self.sleep()
Expand Down Expand Up @@ -526,6 +536,12 @@ def reap_workers(self):
if exitcode == self.APP_LOAD_ERROR:
reason = "App failed to load."
raise HaltServer(reason, self.APP_LOAD_ERROR)
if os.WIFSIGNALED(status):
# Log it later. Not in the SIGCHLD handler. #2564
# https://stackoverflow.com/q/45680378
self.signal_warnings.append(
(wpid, os.WTERMSIG(status))
)

worker = self.WORKERS.pop(wpid, None)
if not worker:
Expand Down

0 comments on commit 01cf842

Please sign in to comment.