mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
fix timeout and socket ssl wrapping
This commit is contained in:
parent
e8e9d285a6
commit
fb53047b73
@ -33,6 +33,7 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
from .. import selectors
|
from .. import selectors
|
||||||
|
|
||||||
|
|
||||||
class TConn():
|
class TConn():
|
||||||
|
|
||||||
def __init__(self, cfg, listener, sock, addr):
|
def __init__(self, cfg, listener, sock, addr):
|
||||||
@ -47,12 +48,12 @@ class TConn():
|
|||||||
# set the socket to non blocking
|
# set the socket to non blocking
|
||||||
self.sock.setblocking(False)
|
self.sock.setblocking(False)
|
||||||
|
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
|
self.sock.setblocking(True)
|
||||||
if self.parser is None:
|
if self.parser is None:
|
||||||
# wrap the socket if needed
|
# wrap the socket if needed
|
||||||
if self.cfg.is_ssl:
|
if self.cfg.is_ssl:
|
||||||
client = ssl.wrap_socket(client, server_side=True,
|
self.sock = ssl.wrap_socket(client, server_side=True,
|
||||||
**self.cfg.ssl_options)
|
**self.cfg.ssl_options)
|
||||||
|
|
||||||
|
|
||||||
@ -142,6 +143,8 @@ class ThreadWorker(base.Worker):
|
|||||||
s.setblocking(False)
|
s.setblocking(False)
|
||||||
self.poller.register(s, selectors.EVENT_READ, self.accept)
|
self.poller.register(s, selectors.EVENT_READ, self.accept)
|
||||||
|
|
||||||
|
timeout = self.cfg.timeout or 0.5
|
||||||
|
|
||||||
while self.alive:
|
while self.alive:
|
||||||
# If our parent changed then we shut down.
|
# If our parent changed then we shut down.
|
||||||
if self.ppid != os.getppid():
|
if self.ppid != os.getppid():
|
||||||
@ -162,7 +165,7 @@ class ThreadWorker(base.Worker):
|
|||||||
# if we more connections than the max number of connections
|
# if we more connections than the max number of connections
|
||||||
# accepted on a worker, wait until some complete or exit.
|
# accepted on a worker, wait until some complete or exit.
|
||||||
if len(self.futures) >= self.worker_connections:
|
if len(self.futures) >= self.worker_connections:
|
||||||
res = futures.wait(self.futures, timeout=self.cfg.timeout)
|
res = futures.wait(self.futures, timeout=timeout)
|
||||||
if not res:
|
if not res:
|
||||||
self.log.info("max requests achieved")
|
self.log.info("max requests achieved")
|
||||||
break
|
break
|
||||||
@ -185,7 +188,6 @@ class ThreadWorker(base.Worker):
|
|||||||
# make sure we close the sockets after the graceful timeout
|
# make sure we close the sockets after the graceful timeout
|
||||||
util.close(sock)
|
util.close(sock)
|
||||||
|
|
||||||
|
|
||||||
def finish_request(self, fs):
|
def finish_request(self, fs):
|
||||||
try:
|
try:
|
||||||
(keepalive, conn) = fs.result()
|
(keepalive, conn) = fs.result()
|
||||||
@ -226,8 +228,6 @@ class ThreadWorker(base.Worker):
|
|||||||
keepalive = False
|
keepalive = False
|
||||||
req = None
|
req = None
|
||||||
try:
|
try:
|
||||||
conn.sock.setblocking(1)
|
|
||||||
|
|
||||||
req = six.next(conn.parser)
|
req = six.next(conn.parser)
|
||||||
if not req:
|
if not req:
|
||||||
return (False, conn)
|
return (False, conn)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user