Skip to content

Commit 6787d0e

Browse files
authored
Merge pull request #52 from consideRatio/pr/start_timeout
ssh: add config option start_timeout
2 parents a195ce9 + 4c2fee5 commit 6787d0e

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

jupyterhub_ssh/__init__.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,28 @@ async def get_user_server_url(self, session, username):
5353

5454
async def start_user_server(self, session, username):
5555
""" """
56+
# REST API reference: https://jupyterhub.readthedocs.io/en/stable/_static/rest-api/index.html#operation--users--name--server-post
57+
# REST API implementation: https://github.com/jupyterhub/jupyterhub/blob/187fe911edce06eb067f736eaf4cc9ea52e69e08/jupyterhub/apihandlers/users.py#L451-L497
5658
create_url = self.app.hub_url / "hub/api/users" / username / "server"
59+
5760
async with session.post(create_url) as resp:
5861
if resp.status == 201 or resp.status == 400:
62+
# FIXME: code 400 can mean "pending stop" or "already running",
63+
# but we assume it means that the server is already
64+
# running.
65+
5966
# Server started quickly
6067
# We manually generate this, even though it's *bad*
6168
# Mostly because when the server is already running, JupyterHub
6269
# doesn't respond with the whole model!
6370
return self.app.hub_url / "user" / username
6471
elif resp.status == 202:
65-
# Server start requested, not done yet
66-
# We check for a while, reporting progress to user - until we're done
72+
# Server start has been requested, now and potentially earlier,
73+
# but hasn't started quickly and is pending spawn.
74+
# We check for a while, reporting progress to user - until we're
75+
# done
6776
try:
68-
# FIXME: Make this configurable?
69-
async with timeout(30):
77+
async with timeout(self.app.start_timeout):
7078
notebook_url = None
7179
self._conn.send_auth_banner("Starting your server...")
7280
while notebook_url is None:
@@ -242,6 +250,15 @@ class JupyterHubSSH(Application):
242250
config=True,
243251
)
244252

253+
start_timeout = Integer(
254+
30,
255+
help="""
256+
Timeout in seconds to wait for a server to start before before closing
257+
the SSH connection.
258+
""",
259+
config=True,
260+
)
261+
245262
def init_logging(self):
246263
"""
247264
Make traitlets & asyncssh logging work properly

0 commit comments

Comments
 (0)