mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-13 04:53:01 +00:00
Fix uncaught exception in pre_spawn_start
This commit is contained in:
@@ -172,7 +172,19 @@ class SpawnHandler(BaseHandler):
|
|||||||
spawner._spawn_future = None
|
spawner._spawn_future = None
|
||||||
# not running, no form. Trigger spawn and redirect back to /user/:name
|
# not running, no form. Trigger spawn and redirect back to /user/:name
|
||||||
f = asyncio.ensure_future(self.spawn_single_user(user, server_name))
|
f = asyncio.ensure_future(self.spawn_single_user(user, server_name))
|
||||||
await asyncio.wait([f], timeout=1)
|
done, pending = await asyncio.wait([f], timeout=1)
|
||||||
|
# If spawn_single_user throws an exception, raise a 500 error
|
||||||
|
# otherwise it may cause a redirect loop
|
||||||
|
if f in done:
|
||||||
|
future, = done
|
||||||
|
exc = future.exception()
|
||||||
|
if exc:
|
||||||
|
raise web.HTTPError(
|
||||||
|
500,
|
||||||
|
"Error in Authenticator.pre_spawn_start: %s %s"
|
||||||
|
% (type(exc).__name__, str(exc)),
|
||||||
|
)
|
||||||
|
return
|
||||||
self.redirect(pending_url)
|
self.redirect(pending_url)
|
||||||
|
|
||||||
@web.authenticated
|
@web.authenticated
|
||||||
|
@@ -529,7 +529,10 @@ class User:
|
|||||||
|
|
||||||
# trigger pre-spawn hook on authenticator
|
# trigger pre-spawn hook on authenticator
|
||||||
authenticator = self.authenticator
|
authenticator = self.authenticator
|
||||||
|
try:
|
||||||
if authenticator:
|
if authenticator:
|
||||||
|
# pre_spawn_start can thow errors that can lead to a redirect loop
|
||||||
|
# if left uncaught (see https://github.com/jupyterhub/jupyterhub/issues/2683)
|
||||||
await maybe_future(authenticator.pre_spawn_start(self, spawner))
|
await maybe_future(authenticator.pre_spawn_start(self, spawner))
|
||||||
|
|
||||||
spawner._start_pending = True
|
spawner._start_pending = True
|
||||||
@@ -539,7 +542,6 @@ class User:
|
|||||||
) = spawner.orm_spawner.last_activity = datetime.utcnow()
|
) = spawner.orm_spawner.last_activity = datetime.utcnow()
|
||||||
db.commit()
|
db.commit()
|
||||||
# wait for spawner.start to return
|
# wait for spawner.start to return
|
||||||
try:
|
|
||||||
# run optional preparation work to bootstrap the notebook
|
# run optional preparation work to bootstrap the notebook
|
||||||
await maybe_future(spawner.run_pre_spawn_hook())
|
await maybe_future(spawner.run_pre_spawn_hook())
|
||||||
if self.settings.get('internal_ssl'):
|
if self.settings.get('internal_ssl'):
|
||||||
|
Reference in New Issue
Block a user