hub-stopped server not calling stop_extension
The UIS stop extension: https://github.com/cylc/cylc-uiserver/blob/da038f00a1c9d6fb6bbf5b2a156bbc4fc7b299a7/cylc/uiserver/app.py#L516-L524
Runs when stopping (keyboard interrupt) the hubless server (cylc gui), however, it isn't run when stopping the server via the hub..
From it's contents I assume it should be run with both forms of stop
I found this while trying to clean up api_tokens for the coming cli-via-uis:
async def stop_extension(self):
# Remove API token if hub spawned
self.log.info(f'HELLO THERE!')
print('HELLO!')
if os.environ.get("JUPYTERHUB_API_TOKEN"):
print('HUB SPAWNED')
else:
print(os.environ)
try:
os.unlink(API_TOKEN_FILE)
except FileNotFoundError:
pass
# stop the async scan task
await self.workflows_mgr.stop()
for sub in self.data_store_mgr.w_subs.values():
sub.stop()
# Shutdown the thread pool executor
self.data_store_mgr.executor.shutdown(wait=False)
# Destroy ZeroMQ context of all sockets
self.workflows_mgr.context.destroy()
The cylc gui stoppage removed the api_token:
where the cylc hub server stop:

didn't:

Pull requests welcome!
This is an Open Source project - please consider contributing a bug fix
yourself (please read CONTRIBUTING.md before starting any work though).
Which versions of Jupyter Hub & Server were you using?
Which versions of Jupyter Hub & Server were you using?
Is there a version where this isn't the case?
jupyter-client==7.3.1
jupyter-server==1.21.0
jupyter-telemetry==0.1.0
jupyter_core==4.11.2
jupyterhub==3.0.0
jupyterlab-pygments==0.2.2
It looks like Jupyter Hub stops the server by deleting the session.
https://github.com/jupyterhub/jupyterhub/blob/aa0ce1c88a8e34da1779cb13d3f36f81a6a24df7/examples/server-api/start-stop-server.py#L113-L150
I'm not sure how the server responds to this, might need some extra logic to get it to call the shutdown logic. This logic also shuts down terminals, kernels, etc.
I'm not sure how the server responds to this, might need some extra logic to get it to call the shutdown logic. This logic also shuts down terminals, kernels, etc.
I'll have a look at the ServerApp (and session) code to see if there's something I can hook into, as it does received a 204 and then waits for the server to stop post session delete.
Ooh, where does the 204 get received? Probably just need to call ServerApp.stop() to trigger the shutdown logic properly.
Here's the PR which added the stop_extension hook: https://github.com/jupyter-server/jupyter_server/pull/526/files
TODO: Check whether this is still the case post the Jupyter Server v2 upgrade.
This is caused by a simple bug in Jupyter Hub, I'm taking a look at fixing it.
Closed by https://github.com/jupyterhub/jupyterhub/pull/4864
(will be passively fixed with the next JupyterHub release)