Skip to content

Commit

Permalink
workaround: reintroduce gevent.Timeout handling
Browse files Browse the repository at this point in the history
This is probably wrong. But less wrong than handling *all*
BaseException. Reports of this happening may be the result of
 some *other* async Timeout in the wsgi app bubbling through to us.

Gevent docs promise:
"[..] if *exception* is the literal ``False``, the timeout is still raised,
   but the context manager suppresses it, so
   the code outside the with-block won't see it."
  • Loading branch information
pajod committed Aug 14, 2024
1 parent 1fcadcb commit 8617c39
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gunicorn/workers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

class Worker:

WORKAROUND_BASE_EXCEPTIONS = () # none

SIGNALS = [getattr(signal, "SIG%s" % x) for x in (
"ABRT HUP QUIT INT TERM USR1 USR2 WINCH CHLD".split()
)]
Expand Down
3 changes: 3 additions & 0 deletions gunicorn/workers/base_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ def handle(self, listener, client, addr):
self.log.debug("Ignoring socket not connected")
else:
self.log.debug("Ignoring EPIPE")
except self.WORKAROUND_BASE_EXCEPTIONS as e:
self.log.warning("Catched async exception (compat workaround). If this is not a bug in your app, please file a report.")
self.handle_error(req, client, addr, e)
except Exception as e:
self.handle_error(req, client, addr, e)
finally:
Expand Down
2 changes: 2 additions & 0 deletions gunicorn/workers/geventlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ def patch_sendfile():

class EventletWorker(AsyncWorker):

WORKAROUND_BASE_EXCEPTIONS = (eventlet.Timeout, )

def patch(self):
hubs.use_hub()
eventlet.monkey_patch()
Expand Down
2 changes: 2 additions & 0 deletions gunicorn/workers/ggevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

class GeventWorker(AsyncWorker):

WORKAROUND_BASE_EXCEPTIONS = (gevent.Timeout, )

server_class = None
wsgi_handler = None

Expand Down
2 changes: 2 additions & 0 deletions gunicorn/workers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ def run_for_multiple(self, timeout):
return

def run(self):
assert len(self.WORKAROUND_BASE_EXCEPTIONS) == 0

# if no timeout is given the worker will never wait and will
# use the CPU for nothing. This minimal timeout prevent it.
timeout = self.timeout or 0.5
Expand Down

0 comments on commit 8617c39

Please sign in to comment.