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