diff --git a/gunicorn/workers/base_async.py b/gunicorn/workers/base_async.py index 6a79d7ed0..9f648a17d 100644 --- a/gunicorn/workers/base_async.py +++ b/gunicorn/workers/base_async.py @@ -36,7 +36,8 @@ def handle(self, listener, client, addr): parser = http.RequestParser(self.cfg, client, addr) try: listener_name = listener.getsockname() - if not self.cfg.keepalive: + # do not allow keepalive if the worker is about to be restarted + if not self.cfg.keepalive or not self.alive: req = next(parser) self.handle_request(listener_name, req, client, addr) else: diff --git a/gunicorn/workers/ggevent.py b/gunicorn/workers/ggevent.py index 2125a32d0..844e196a7 100644 --- a/gunicorn/workers/ggevent.py +++ b/gunicorn/workers/ggevent.py @@ -87,6 +87,11 @@ def run(self): self.notify() gevent.sleep(1.0) + # wait for the keepalive period to end before stopping the acceptance of new requests + ts = time.time() + while time.time() - ts <= self.cfg.keepalive: + gevent.sleep(1.0) + try: # Stop accepting requests for server in servers: