add User.proxy_pending

flag for waiting for the proxy to be updated

avoids User.running being True when the user's server has not yet been added to the proxy,
causing potential redirect loops.
This commit is contained in:
Min RK
2017-07-14 14:57:06 +02:00
parent dca530d2c0
commit a79071bb33
2 changed files with 15 additions and 5 deletions

View File

@@ -321,6 +321,7 @@ class BaseHandler(RequestHandler):
tic = IOLoop.current().time() tic = IOLoop.current().time()
f = user.spawn(options) f = user.spawn(options)
user.proxy_pending = True
@gen.coroutine @gen.coroutine
def finish_user_spawn(f=None): def finish_user_spawn(f=None):
@@ -335,8 +336,16 @@ class BaseHandler(RequestHandler):
toc = IOLoop.current().time() toc = IOLoop.current().time()
self.log.info("User %s server took %.3f seconds to start", user.name, toc-tic) self.log.info("User %s server took %.3f seconds to start", user.name, toc-tic)
self.statsd.timing('spawner.success', (toc - tic) * 1000) self.statsd.timing('spawner.success', (toc - tic) * 1000)
yield self.proxy.add_user(user) try:
user.spawner.add_poll_callback(self.user_stopped, user) yield self.proxy.add_user(user)
except Exception:
self.log.exception("Failed to add user %s to proxy!", user)
self.log.error("Stopping user %s to avoid inconsistent state")
yield user.stop()
else:
user.spawner.add_poll_callback(self.user_stopped, user)
finally:
user.proxy_pending = False
try: try:
yield gen.with_timeout(timedelta(seconds=self.slow_spawn_timeout), f) yield gen.with_timeout(timedelta(seconds=self.slow_spawn_timeout), f)
@@ -532,7 +541,7 @@ class UserSpawnHandler(BaseHandler):
# logged in as correct user, spawn the server # logged in as correct user, spawn the server
if current_user.spawner: if current_user.spawner:
if current_user.spawn_pending: if current_user.spawn_pending or current_user.proxy_pending:
# spawn has started, but not finished # spawn has started, but not finished
self.statsd.incr('redirects.user_spawn_pending', 1) self.statsd.incr('redirects.user_spawn_pending', 1)
html = self.render_template("spawn_pending.html", user=current_user) html = self.render_template("spawn_pending.html", user=current_user)

View File

@@ -110,6 +110,7 @@ class User(HasTraits):
spawner = None spawner = None
spawn_pending = False spawn_pending = False
stop_pending = False stop_pending = False
proxy_pending = False
waiting_for_response = False waiting_for_response = False
@property @property
@@ -158,8 +159,8 @@ class User(HasTraits):
@property # FIX-ME CHECK IF STILL NEEDED @property # FIX-ME CHECK IF STILL NEEDED
def running(self): def running(self):
"""property for whether a user has a running server""" """property for whether a user has a fully running, accessible server"""
if self.spawn_pending or self.stop_pending: if self.spawn_pending or self.stop_pending or self.proxy_pending:
return False # server is not running if spawn or stop is still pending return False # server is not running if spawn or stop is still pending
if self.server is None: if self.server is None:
return False return False