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): ...@@ -78,7 +78,13 @@ class ThreadingWSGIServer(ThreadingMixIn, WSGIServer):
def __init__(self, server_address, *args, **kw): def __init__(self, server_address, *args, **kw):
self.address_family, _, _, _, _ = socket.getaddrinfo(*server_address)[0] 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): def server_bind(self):
if self.address_family == socket.AF_INET6: if self.address_family == socket.AF_INET6:
...@@ -86,14 +92,6 @@ class ThreadingWSGIServer(ThreadingMixIn, WSGIServer): ...@@ -86,14 +92,6 @@ class ThreadingWSGIServer(ThreadingMixIn, WSGIServer):
self.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1) self.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1)
WSGIServer.server_bind(self) 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): class CaucaseWSGIRequestHandler(WSGIRequestHandler):
""" """
Make WSGIRequestHandler logging more apache-like. Make WSGIRequestHandler logging more apache-like.
...@@ -516,7 +514,7 @@ def main(argv=None, until=utils.until): ...@@ -516,7 +514,7 @@ def main(argv=None, until=utils.until):
host=host, host=host,
port=https_port, port=https_port,
app=application, app=application,
server_class=ThreadingWSGISSLServer, server_class=ThreadingWSGIServer,
handler_class=CaucaseSSLWSGIRequestHandler, handler_class=CaucaseSSLWSGIRequestHandler,
), ),
) )
...@@ -534,12 +532,6 @@ def main(argv=None, until=utils.until): ...@@ -534,12 +532,6 @@ def main(argv=None, until=utils.until):
sock=https.socket, sock=https.socket,
server_side=True, server_side=True,
) )
try:
https.server_bind()
https.server_activate()
except:
https.server_close()
raise
if args.backup_directory: if args.backup_directory:
backup_period = datetime.timedelta(args.backup_period, 0) backup_period = datetime.timedelta(args.backup_period, 0)
try: try:
...@@ -558,6 +550,12 @@ def main(argv=None, until=utils.until): ...@@ -558,6 +550,12 @@ def main(argv=None, until=utils.until):
else: else:
next_backup = None next_backup = None
for server in itertools.chain(http_list, https_list): for server in itertools.chain(http_list, https_list):
try:
server.server_bind()
server.server_activate()
except:
server.server_close()
raise
startServerThread(server) startServerThread(server)
try: try:
while True: 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