diff --git a/confluent_server/confluent/httpapi.py b/confluent_server/confluent/httpapi.py index 445d6be2..9e7ed2df 100644 --- a/confluent_server/confluent/httpapi.py +++ b/confluent_server/confluent/httpapi.py @@ -35,6 +35,7 @@ import eventlet.greenthread import greenlet import json import socket +import sys import traceback import time import urlparse @@ -741,9 +742,20 @@ def serve(bind_host, bind_port): #but deps are simpler without flup #also, the potential for direct http can be handy #todo remains unix domain socket for even http - eventlet.wsgi.server( - eventlet.listen((bind_host, bind_port, 0, 0), family=socket.AF_INET6), - resourcehandler, log=False, log_output=False, debug=False) + sock = None + while not sock: + try: + sock = eventlet.listen( + (bind_host, bind_port, 0, 0), family=socket.AF_INET6) + except socket.error as e: + if e.errno != 98: + raise + sys.stderr.write( + 'Failed to open HTTP due to busy port, trying again in' + ' a second\n') + eventlet.sleep(1) + eventlet.wsgi.server(sock, resourcehandler, log=False, log_output=False, + debug=False) class HttpApi(object): diff --git a/confluent_server/confluent/sockapi.py b/confluent_server/confluent/sockapi.py index 874372d0..8205d7e3 100644 --- a/confluent_server/confluent/sockapi.py +++ b/confluent_server/confluent/sockapi.py @@ -244,7 +244,16 @@ def _tlshandler(bind_host, bind_port): plainsocket = socket.socket(socket.AF_INET6) plainsocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) plainsocket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) - plainsocket.bind((bind_host, bind_port, 0, 0)) + bound = False + while not bound: + try: + plainsocket.bind((bind_host, bind_port, 0, 0)) + bound = True + except socket.error as e: + if e.errno != 98: + raise + sys.stderr.write('TLS Socket in use, retrying in 1 second\n') + eventlet.sleep(1) plainsocket.listen(5) while (1): # TODO: exithook cnn, addr = plainsocket.accept()