Skip to content

Commit

Permalink
Make force close on max requests consistent
Browse files Browse the repository at this point in the history
All worker types should force a connection close after a request that
exceeds the max requests. A worker only needs to log about the automatic
restart once, rather than once for each keepalive request.
  • Loading branch information
tilgovi committed Apr 20, 2020
1 parent 4591b51 commit ebb41da
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions gunicorn/workers/base_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ def handle_request(self, listener_name, req, sock, addr):
listener_name, self.cfg)
environ["wsgi.multithread"] = True
self.nr += 1
if self.alive and self.nr >= self.max_requests:
self.log.info("Autorestarting worker after current request.")
if self.nr >= self.max_requests:
if self.alive:
self.log.info("Autorestarting worker after current request.")
self.alive = False
resp.force_close()
self.alive = False

if not self.cfg.keepalive:
resp.force_close()
Expand Down
5 changes: 3 additions & 2 deletions gunicorn/workers/gthread.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,10 @@ def handle_request(self, req, conn):
environ["wsgi.multithread"] = True
self.nr += 1
if self.nr >= self.max_requests:
self.log.info("Autorestarting worker after current request.")
if self.alive:
self.log.info("Autorestarting worker after current request.")
self.alive = False
resp.force_close()
self.alive = False

if not self.cfg.keepalive:
resp.force_close()
Expand Down

0 comments on commit ebb41da

Please sign in to comment.