diff --git a/THANKS b/THANKS index 9f4c6b6b9..a08cef7da 100644 --- a/THANKS +++ b/THANKS @@ -20,6 +20,7 @@ Andreas Stührk Andrew Burdo Andrew Svetlov Anil V +Ankush Menat Antoine Girard Anton Vlasenko Artur Kruchinin diff --git a/docs/source/settings.rst b/docs/source/settings.rst index e1e91fa76..511dc69fb 100644 --- a/docs/source/settings.rst +++ b/docs/source/settings.rst @@ -1793,3 +1793,6 @@ set this to a higher value. ``sync`` worker does not support persistent connections and will ignore this option. +.. note:: + When the worker becomes idle, some connections may remain open for + up to twice the specified keepalive value. diff --git a/gunicorn/workers/gthread.py b/gunicorn/workers/gthread.py index 7a23228cd..57955c982 100644 --- a/gunicorn/workers/gthread.py +++ b/gunicorn/workers/gthread.py @@ -206,8 +206,13 @@ def run(self): # can we accept more connections? if self.nr_conns < self.worker_connections: + # Block for new events until worker times out or keepalive timeout. + select_timeout = self.timeout or 1.0 + if self._keep: + select_timeout = min(select_timeout, self.cfg.keepalive) + # wait for an event - events = self.poller.select(1.0) + events = self.poller.select(select_timeout) for key, _ in events: callback = key.data callback(key.fileobj)