From f565f8ac5372063291d361cd9103b403ff2f8f5e Mon Sep 17 00:00:00 2001 From: Min RK Date: Tue, 1 Mar 2016 15:18:51 +0100 Subject: [PATCH] Don't add users with spawn_pending to the proxy check_routes checks for missing routes for running users. This is meant for when the proxy has been relaunched outside the Hub. If spawners are slow to start, it's possible for check_routes to fire in the middle of spawning, triggering addition of the user's server (which has no defined location yet) to the proxy before it's up. If the spawning fails, the route will remain indefinitely (because it never should have been added in the first place), and the user will see 503 until their server is launched manually again. Checking `spawn_pending` in user.running prevents this. --- jupyterhub/orm.py | 8 +++++++- jupyterhub/user.py | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/jupyterhub/orm.py b/jupyterhub/orm.py index 2a61b937..0f1fb437 100644 --- a/jupyterhub/orm.py +++ b/jupyterhub/orm.py @@ -178,6 +178,9 @@ class Proxy(Base): self.log.info("Adding user %s to proxy %s => %s", user.name, user.proxy_path, user.server.host, ) + if user.spawn_pending: + raise RuntimeError( + "User %s's spawn is pending, shouldn't be added to the proxy yet!", user.name) yield self.api_request(user.proxy_path, method='POST', @@ -213,7 +216,7 @@ class Proxy(Base): futures = [] for orm_user in db.query(User): user = user_dict[orm_user] - if (user.server): + if user.running: futures.append(self.add_user(user)) # wait after submitting them all for f in futures: @@ -230,6 +233,9 @@ class Proxy(Base): db = inspect(self).session for orm_user in db.query(User).filter(User.server != None): user = user_dict[orm_user] + if not user.running: + # Don't add users to the proxy that haven't finished starting + continue if user.server is None: # This should never be True, but seems to be on rare occasion. # catch filter bug, either in sqlalchemy or my understanding of its behavior diff --git a/jupyterhub/user.py b/jupyterhub/user.py index fafd67ff..cf4a91ae 100644 --- a/jupyterhub/user.py +++ b/jupyterhub/user.py @@ -145,6 +145,8 @@ class User(HasTraits): @property def running(self): """property for whether a user has a running server""" + if self.spawn_pending: + return False # server is not running if spawn is still pending if self.server is None: return False return True