mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-16 22:43:00 +00:00
better handle servers failing to start
including more informative TimeoutError messages
This commit is contained in:
@@ -54,6 +54,7 @@ class JSONDict(TypeDecorator):
|
|||||||
|
|
||||||
|
|
||||||
Base = declarative_base()
|
Base = declarative_base()
|
||||||
|
Base.log = app_log
|
||||||
|
|
||||||
|
|
||||||
class Server(Base):
|
class Server(Base):
|
||||||
@@ -121,7 +122,6 @@ class Proxy(Base):
|
|||||||
public_server = relationship(Server, primaryjoin=_public_server_id == Server.id)
|
public_server = relationship(Server, primaryjoin=_public_server_id == Server.id)
|
||||||
_api_server_id = Column(Integer, ForeignKey('servers.id'))
|
_api_server_id = Column(Integer, ForeignKey('servers.id'))
|
||||||
api_server = relationship(Server, primaryjoin=_api_server_id == Server.id)
|
api_server = relationship(Server, primaryjoin=_api_server_id == Server.id)
|
||||||
log = app_log
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
if self.public_server:
|
if self.public_server:
|
||||||
@@ -191,7 +191,7 @@ class Proxy(Base):
|
|||||||
def get_routes(self, client=None):
|
def get_routes(self, client=None):
|
||||||
"""Fetch the proxy's routes"""
|
"""Fetch the proxy's routes"""
|
||||||
resp = yield self.api_request('', client=client)
|
resp = yield self.api_request('', client=client)
|
||||||
raise gen.Return(json.loads(resp.body.decode('utf8', 'replace')))
|
return json.loads(resp.body.decode('utf8', 'replace'))
|
||||||
|
|
||||||
|
|
||||||
class Hub(Base):
|
class Hub(Base):
|
||||||
@@ -317,9 +317,21 @@ class User(Base):
|
|||||||
self.state = spawner.get_state()
|
self.state = spawner.get_state()
|
||||||
self.last_activity = datetime.utcnow()
|
self.last_activity = datetime.utcnow()
|
||||||
db.commit()
|
db.commit()
|
||||||
|
try:
|
||||||
yield self.server.wait_up(http=True)
|
yield self.server.wait_up(http=True)
|
||||||
raise gen.Return(self)
|
except TimeoutError as e:
|
||||||
|
self.log.warn("{user}'s server never started at {url}, giving up.".format(
|
||||||
|
user=self.name, url=self.server.url,
|
||||||
|
))
|
||||||
|
try:
|
||||||
|
yield self.stop()
|
||||||
|
except Exception:
|
||||||
|
self.log.error("Failed to cleanup {user}'s server that failed to start".format(
|
||||||
|
user=self.name,
|
||||||
|
), exc_info=True)
|
||||||
|
# raise original TimeoutError
|
||||||
|
raise e
|
||||||
|
return self
|
||||||
|
|
||||||
@gen.coroutine
|
@gen.coroutine
|
||||||
def stop(self):
|
def stop(self):
|
||||||
|
@@ -45,7 +45,9 @@ def wait_for_server(ip, port, timeout=10):
|
|||||||
yield gen.Task(loop.add_timeout, loop.time() + 0.1)
|
yield gen.Task(loop.add_timeout, loop.time() + 0.1)
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
raise TimeoutError
|
raise TimeoutError("Server at {ip}:{port} didn't respond in {timeout} seconds".format(
|
||||||
|
**locals()
|
||||||
|
))
|
||||||
|
|
||||||
@gen.coroutine
|
@gen.coroutine
|
||||||
def wait_for_http_server(url, timeout=10):
|
def wait_for_http_server(url, timeout=10):
|
||||||
@@ -77,7 +79,9 @@ def wait_for_http_server(url, timeout=10):
|
|||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
raise TimeoutError
|
raise TimeoutError("Server at {url} didn't respond in {timeout} seconds".format(
|
||||||
|
**locals()
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
# Decorators for authenticated Handlers
|
# Decorators for authenticated Handlers
|
||||||
@@ -166,3 +170,4 @@ def compare_token(compare, token):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user