mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-19 07:53:00 +00:00
Merge branch 'master' into named_servers
This commit is contained in:
@@ -48,6 +48,12 @@ def can_connect(ip, port):
|
||||
else:
|
||||
return True
|
||||
|
||||
# exponential falloff factors:
|
||||
# start at 100ms, falloff by 2x
|
||||
# never longer than 5s
|
||||
DT_MIN = 0.1
|
||||
DT_SCALE = 2
|
||||
DT_MAX = 5
|
||||
|
||||
@gen.coroutine
|
||||
def wait_for_server(ip, port, timeout=10):
|
||||
@@ -56,11 +62,13 @@ def wait_for_server(ip, port, timeout=10):
|
||||
ip = '127.0.0.1'
|
||||
loop = ioloop.IOLoop.current()
|
||||
tic = loop.time()
|
||||
while loop.time() - tic < timeout:
|
||||
dt = DT_MIN
|
||||
while dt > 0:
|
||||
if can_connect(ip, port):
|
||||
return
|
||||
else:
|
||||
yield gen.sleep(0.1)
|
||||
yield gen.sleep(dt)
|
||||
dt = min(dt * DT_SCALE, DT_MAX, timeout - (loop.time() - tic))
|
||||
raise TimeoutError(
|
||||
"Server at {ip}:{port} didn't respond in {timeout} seconds".format(**locals())
|
||||
)
|
||||
@@ -75,7 +83,8 @@ def wait_for_http_server(url, timeout=10):
|
||||
loop = ioloop.IOLoop.current()
|
||||
tic = loop.time()
|
||||
client = AsyncHTTPClient()
|
||||
while loop.time() - tic < timeout:
|
||||
dt = DT_MIN
|
||||
while dt > 0:
|
||||
try:
|
||||
r = yield client.fetch(url, follow_redirects=False)
|
||||
except HTTPError as e:
|
||||
@@ -86,16 +95,17 @@ def wait_for_http_server(url, timeout=10):
|
||||
# but 502 or other proxy error is conceivable
|
||||
app_log.warning(
|
||||
"Server at %s responded with error: %s", url, e.code)
|
||||
yield gen.sleep(0.1)
|
||||
yield gen.sleep(dt)
|
||||
else:
|
||||
app_log.debug("Server at %s responded with %s", url, e.code)
|
||||
return e.response
|
||||
except (OSError, socket.error) as e:
|
||||
if e.errno not in {errno.ECONNABORTED, errno.ECONNREFUSED, errno.ECONNRESET}:
|
||||
app_log.warning("Failed to connect to %s (%s)", url, e)
|
||||
yield gen.sleep(0.1)
|
||||
yield gen.sleep(dt)
|
||||
else:
|
||||
return r
|
||||
dt = min(dt * DT_SCALE, DT_MAX, timeout - (loop.time() - tic))
|
||||
|
||||
raise TimeoutError(
|
||||
"Server at {url} didn't respond in {timeout} seconds".format(**locals())
|
||||
|
Reference in New Issue
Block a user