Skip to content

Commit

Permalink
Fix gunicorn signal bug (#6134)
Browse files Browse the repository at this point in the history
* Fix resetting SIGCHLD in Gunicorn Worker

* add CONTRIBUTORS and add CHANGES

* add CONTRIBUTORS and add CHANGES

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* change CHANGES spell

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update aiohttp/worker.py

* Fix line length

Co-authored-by: liuyixin <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Andrew Svetlov <[email protected]>
  • Loading branch information
4 people authored Oct 27, 2021
1 parent dccf502 commit 0fef0a3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES/6130.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix resetting `SIGCHLD` signals in Gunicorn aiohttp Worker to fix `subprocesses` that capture output having an incorrect `returncode`.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ Gustavo Carneiro
Günther Jena
Hans Adema
Harmon Y.
Harry Liu
Hiroshi Ogawa
Hrishikesh Paranjape
Hu Bo
Expand Down
8 changes: 8 additions & 0 deletions aiohttp/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ def init_signals(self) -> None:
# by interrupting system calls
signal.siginterrupt(signal.SIGTERM, False)
signal.siginterrupt(signal.SIGUSR1, False)
# Reset signals so Gunicorn doesn't swallow subprocess return codes
# See: https://github.com/aio-libs/aiohttp/issues/6130
if sys.version_info < (3, 8):
# Starting from Python 3.8,
# the default child watcher is ThreadedChildWatcher.
# The watcher doesn't depend on SIGCHLD signal,
# there is no need to reset it.
signal.signal(signal.SIGCHLD, signal.SIG_DFL)

def handle_quit(self, sig: int, frame: FrameType) -> None:
self.alive = False
Expand Down

0 comments on commit 0fef0a3

Please sign in to comment.