Skip to content

Commit

Permalink
3227: Wait for the keepalive period to end before stopping the accept…
Browse files Browse the repository at this point in the history
…ance of new requests. This will prevent potential disruptions in request handling.
  • Loading branch information
Michal Daniliszyn 1 committed Jul 4, 2024
1 parent 9802e21 commit 29b7866
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion gunicorn/workers/base_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions gunicorn/workers/ggevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 29b7866

Please sign in to comment.