Commit 6719a054 authored by Vincent Pelletier's avatar Vincent Pelletier Committed by Vincent Pelletier

http: Start listening only once all sockets are ready and wrapped.

Rather than starting to listen on http before https.
This makes tests more reliable, as they will no actually wait for caucased
to be fully ready, in turn making shutdown more reliable.
parent 23b99a24
......@@ -78,7 +78,13 @@ class ThreadingWSGIServer(ThreadingMixIn, WSGIServer):
def __init__(self, server_address, *args, **kw):
self.address_family, _, _, _, _ = socket.getaddrinfo(*server_address)[0]
WSGIServer.__init__(self, server_address, *args, **kw)
WSGIServer.__init__(
self,
server_address,
bind_and_activate=False,
*args,
**kw
)
def server_bind(self):
if self.address_family == socket.AF_INET6:
......@@ -86,14 +92,6 @@ class ThreadingWSGIServer(ThreadingMixIn, WSGIServer):
self.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1)
WSGIServer.server_bind(self)
class ThreadingWSGISSLServer(ThreadingWSGIServer):
"""
Threading WSGI SSL server
Delay socket opening to leave time for socket wrapping.
"""
def __init__(self, *args, **kw):
ThreadingWSGIServer.__init__(self, bind_and_activate=False, *args, **kw)
class CaucaseWSGIRequestHandler(WSGIRequestHandler):
"""
Make WSGIRequestHandler logging more apache-like.
......@@ -516,7 +514,7 @@ def main(argv=None, until=utils.until):
host=host,
port=https_port,
app=application,
server_class=ThreadingWSGISSLServer,
server_class=ThreadingWSGIServer,
handler_class=CaucaseSSLWSGIRequestHandler,
),
)
......@@ -534,12 +532,6 @@ def main(argv=None, until=utils.until):
sock=https.socket,
server_side=True,
)
try:
https.server_bind()
https.server_activate()
except:
https.server_close()
raise
if args.backup_directory:
backup_period = datetime.timedelta(args.backup_period, 0)
try:
......@@ -558,6 +550,12 @@ def main(argv=None, until=utils.until):
else:
next_backup = None
for server in itertools.chain(http_list, https_list):
try:
server.server_bind()
server.server_activate()
except:
server.server_close()
raise
startServerThread(server)
try:
while True:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment