Join GitHub today
Redirection when spawner is pending #1534
Currently in jupyterhub when a user is pending a spawn and clicks the home button it will redirect
def get(self): user = self.get_current_user() if user.running: # trigger poll_and_notify event in case of a server that died yield user.spawner.poll_and_notify() # send the user to /spawn if they aren't running, # to establish that this is an explicit spawn request rather # than an implicit one, which can be caused by any link to `/user/:name` url = user.url if user.running else url_path_join(self.hub.base_url, 'spawn') html = self.render_template('home.html', user=user, url=url, ) self.finish(html)
This brings up the option for the user to "Start my server" again. When not using any options form the user will be redirected back to /user/:name if they click the "Start my server" button. However, when using an options form and the "Start my server" button is clicked, it will always redirect the user back to the options form as long as the user is pending:
user = self.get_current_user() if not self.allow_named_servers and user.running: url = user.url self.log.debug("User is running: %s", url) self.redirect(url) return if user.spawner.options_form: self.finish(self._render_form()) else: # Explicit spawn request: clear _spawn_future # which may have been saved to prevent implicit spawns # after a failure. if user.spawner._spawn_future and user.spawner._spawn_future.done(): user.spawner._spawn_future = None # not running, no form. Trigger spawn by redirecting to /user/:name self.redirect(user.url)
From here the user will consequently receive an error 400 for every request to start a server.
@web.authenticated @gen.coroutine def post(self): """POST spawns with user-specified options""" user = self.get_current_user() if not self.allow_named_servers and user.running: url = user.url self.log.warning("User is already running: %s", url) self.redirect(url) return if user.spawner.pending: raise web.HTTPError( 400, "%s is pending %s" % (user.spawner._log_name, user.spawner.pending) ) ...
I propose that if the spawner is pending, instead of having the user even be presented with the option to "Start my server" always redirect them to /hub/user/:name when the home button is clicked and the spawner is pending. This not only solves the bug of when a options form is used and the user is unable to get to their notebook without explicitly changing the url, but also in terms of usability, it stops the user from undergoing the experience of being able to repeatedly click "Start my server" for the duration of the spawner pending. See my PR for the minor changes needed to get this functionality. #1533