From 14edf034b4cd5d667c9e13ff0a280cab103c7a76 Mon Sep 17 00:00:00 2001 From: Mingxuan Lin Date: Wed, 7 Nov 2018 14:51:45 +0100 Subject: [PATCH] Fix for the terminal shutdown issue This patch prevents creation of a new terminal when handling websocket handshaking request. The default behavior of `terminado.NamedTermManager` is to automatically start a new terminal in response to a websocket handshake, which prevents a terminal from being properly shut down in JupyterLab as reported in this [issue](jupyterlab/jupyterlab#5061). --- notebook/terminal/handlers.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/notebook/terminal/handlers.py b/notebook/terminal/handlers.py index 6a66aa2f0f..7e74ed67df 100644 --- a/notebook/terminal/handlers.py +++ b/notebook/terminal/handlers.py @@ -31,6 +31,8 @@ def origin_check(self): def get(self, *args, **kwargs): if not self.get_current_user(): raise web.HTTPError(403) + if not args[0] in self.term_manager.terminals: + raise web.HTTPError(404) return super(TermSocket, self).get(*args, **kwargs) def on_message(self, message):