cylc-uiserver icon indicating copy to clipboard operation
cylc-uiserver copied to clipboard

hub-stopped server not calling stop_extension

Open dwsutherland opened this issue 3 years ago • 6 comments

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: image where the cylc hub server stop: image

didn't: image

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).

dwsutherland avatar Oct 20 '22 04:10 dwsutherland

Which versions of Jupyter Hub & Server were you using?

oliver-sanders avatar Oct 31 '22 09:10 oliver-sanders

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

dwsutherland avatar Nov 10 '22 03:11 dwsutherland

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.

oliver-sanders avatar Nov 14 '22 11:11 oliver-sanders

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.

dwsutherland avatar Nov 28 '22 07:11 dwsutherland

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

oliver-sanders avatar Nov 28 '22 15:11 oliver-sanders

TODO: Check whether this is still the case post the Jupyter Server v2 upgrade.

oliver-sanders avatar Aug 11 '23 14:08 oliver-sanders

This is caused by a simple bug in Jupyter Hub, I'm taking a look at fixing it.

oliver-sanders avatar Aug 08 '24 08:08 oliver-sanders

Closed by https://github.com/jupyterhub/jupyterhub/pull/4864

(will be passively fixed with the next JupyterHub release)

oliver-sanders avatar Aug 09 '24 12:08 oliver-sanders