mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 02:49:12 +08:00
fix: Request timeout for gthread workers (#1)
* ci: drop unsupported versions * fix: a *dirty* request timeout for gthread workers * fix: drain current futures before exiting * fix: avoid accepting new connections completely * refactor: Just rely on graceful_timeout This has minor side effect of no progress on accepted BUT not "read" reqeusts. But I feel this makes code simpler and less prone to bugs. These time outs should be *rare* and fixed anyway.
This commit is contained in:
parent
bacbf8aa51
commit
0c9b266790
7
.github/workflows/tox.yml
vendored
7
.github/workflows/tox.yml
vendored
@ -21,16 +21,9 @@ jobs:
|
||||
- macos-13
|
||||
# Not testing Windows, because tests need Unix-only fcntl, grp, pwd, etc.
|
||||
python-version:
|
||||
# CPython <= 3.7 is EoL since 2023-06-27
|
||||
- "3.7"
|
||||
- "3.8"
|
||||
- "3.9"
|
||||
- "3.10"
|
||||
- "3.11"
|
||||
- "3.12"
|
||||
# PyPy <= 3.8 is EoL since 2023-06-16
|
||||
- "pypy-3.9"
|
||||
- "pypy-3.10"
|
||||
include:
|
||||
# Note: potentially "universal2" release
|
||||
# https://github.com/actions/runner-images/issues/9741
|
||||
|
||||
@ -107,6 +107,7 @@ class ThreadWorker(base.Worker):
|
||||
|
||||
def _wrap_future(self, fs, conn):
|
||||
fs.conn = conn
|
||||
fs._request_timeout = time.monotonic() + self.cfg.timeout
|
||||
self.futures.append(fs)
|
||||
fs.add_done_callback(self.finish_request)
|
||||
|
||||
@ -230,6 +231,14 @@ class ThreadWorker(base.Worker):
|
||||
# handle keepalive timeouts
|
||||
self.murder_keepalived()
|
||||
|
||||
# `gthread` does not implement ANY kind of request timeout, the
|
||||
# simplest request timeout will kill the entire worker.
|
||||
current_time = time.monotonic()
|
||||
for fut in self.futures:
|
||||
if current_time > fut._request_timeout:
|
||||
self.alive = False
|
||||
self.log.error("A request timed out. Exiting.")
|
||||
|
||||
self.tpool.shutdown(False)
|
||||
self.poller.close()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user