mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Compare commits
No commits in common. "bb554053bb87218120d76ab6676af7015680e8b6" and "72c1e495d89259151e73947a057432d528b06bb0" have entirely different histories.
bb554053bb
...
72c1e495d8
@ -5,7 +5,6 @@ This is a fork of gunicorn with the following changes:
|
||||
|
||||
1. Request timeout implementation for `gthread` - https://github.com/frappe/gunicorn/pull/1 (upstream doesn't have any, we NEED this.)
|
||||
2. Higher timeout for `selector` - https://github.com/frappe/gunicorn/pull/2 (This is a small optional performance improvement)
|
||||
3. https://github.com/benoitc/gunicorn/pull/2918 is reverted to avoid connection resets while draining or restarting a worker.
|
||||
|
||||
Note to anyone upgrading/adding changes:
|
||||
- Pull upstream changes
|
||||
|
||||
@ -1177,7 +1177,7 @@ class Group(Setting):
|
||||
Switch worker process to run as this group.
|
||||
|
||||
A valid group id (as an integer) or the name of a user that can be
|
||||
retrieved with a call to ``grp.getgrnam(value)`` or ``None`` to not
|
||||
retrieved with a call to ``pwd.getgrnam(value)`` or ``None`` to not
|
||||
change the worker processes group.
|
||||
"""
|
||||
|
||||
|
||||
@ -41,12 +41,15 @@ class TConn:
|
||||
|
||||
self.timeout = None
|
||||
self.parser = None
|
||||
self.initialized = False
|
||||
|
||||
# set the socket to non blocking
|
||||
self.sock.setblocking(False)
|
||||
|
||||
def init(self):
|
||||
self.initialized = True
|
||||
self.sock.setblocking(True)
|
||||
|
||||
if self.parser is None:
|
||||
# wrap the socket if needed
|
||||
if self.cfg.is_ssl:
|
||||
@ -127,23 +130,27 @@ class ThreadWorker(base.Worker):
|
||||
conn = TConn(self.cfg, sock, client, server)
|
||||
|
||||
self.nr_conns += 1
|
||||
# enqueue the job
|
||||
self.enqueue_req(conn)
|
||||
# wait until socket is readable
|
||||
with self._lock:
|
||||
self.poller.register(conn.sock, selectors.EVENT_READ,
|
||||
partial(self.on_client_socket_readable, conn))
|
||||
except OSError as e:
|
||||
if e.errno not in (errno.EAGAIN, errno.ECONNABORTED,
|
||||
errno.EWOULDBLOCK):
|
||||
raise
|
||||
|
||||
def reuse_connection(self, conn, client):
|
||||
def on_client_socket_readable(self, conn, client):
|
||||
with self._lock:
|
||||
# unregister the client from the poller
|
||||
self.poller.unregister(client)
|
||||
# remove the connection from keepalive
|
||||
try:
|
||||
self._keep.remove(conn)
|
||||
except ValueError:
|
||||
# race condition
|
||||
return
|
||||
|
||||
if conn.initialized:
|
||||
# remove the connection from keepalive
|
||||
try:
|
||||
self._keep.remove(conn)
|
||||
except ValueError:
|
||||
# race condition
|
||||
return
|
||||
|
||||
# submit the connection to a worker
|
||||
self.enqueue_req(conn)
|
||||
@ -278,7 +285,7 @@ class ThreadWorker(base.Worker):
|
||||
|
||||
# add the socket to the event loop
|
||||
self.poller.register(conn.sock, selectors.EVENT_READ,
|
||||
partial(self.reuse_connection, conn))
|
||||
partial(self.on_client_socket_readable, conn))
|
||||
else:
|
||||
self.nr_conns -= 1
|
||||
conn.close()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user