-
Notifications
You must be signed in to change notification settings - Fork 293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remote jupyter doesn't reconnect after computer sleeps #1654
Comments
Thanks for the issue @8enmann. |
Any updates? |
Hi @8enmann, this issue is parked for now, we'll come back to it if other people run into it. In the mean time I have a question. You mentioned you loose your cells, does that happen even if you save the notebook? |
The problem is not that the cell goes away, it's that I need to restart the notebook in order to run cells since the remote session is disposed. Saving or not doesn't make a difference. |
I see, I'm glad there's a workaround. We're not planning to fix this one on our next release. We'll let the issue open for people to upvote it and will revisit it on triage after the august release. |
I've got the same problem. Is there any way to get at the debug logs for reconnection -- it feels like I don't have good access to what the jupyter plugin is doing to try to reconnect. |
@aray-openai those should be on the webview developer tools: |
Hi vscode team, I've run into this porblem too. |
Hi @shikiponn, please share with us what your Python output tab on the Panel says when the issue happens. |
Issue Type: Bug Same basic problem. It happens when there is even the slightest interruption to my corporate VPN connection. It is so bad for my overseas colleagues, that despite me trying to get them to use the Python extension in VS Code, they refuse, as it is too frustrating to have the session get "disposed" every few minutes. Instead, they choose to use either Jupyter Labs or Notebooks, as those do not have any issue picking up right where it was before the network disruption. The reported VS Code Python Extension error is: Why is it that Jupyter Labs or Notebooks do not have any problems reconnecting to the Jupyter Session running on a remote computer after a slight network disruption and now the Python extension for VS Code cannot handle it? This was not a problem a year or so ago. With the VS Code Python Extension, I used to be able to:
Why and how was this broken? Why does this still work in Jupyter Labs or Notebooks? Might be related to what IanMatthewHuff said in this issue comment:
Extension version: 2020.9.114305 System Info
|
This is because of how we manage kernels. When our UI is disposed, we close the kernel connection. Whereas with jupyter you start a server and close kernels when you shutdown the server. Likely what's happening when you put your computer to sleep, VS code is disposing of our Webview UI, causing our dispose method to be called. In order to accommodate this we'd need some sort of kernel management UI (other than just closing windows). Something like this bug here: |
@rchiodo that is exactly the issue. If those features were added, I think that would solve this issue. Concise description of my experience: I believe this issue could be rolled up into that issue/feature request. |
I should note the usual way I run python. From PowerShell on local computer:
Then copy the displayed link into
Then the VS Code Python Extension works great, at least until a slight network interruption or my local computer goes to sleep. |
Any updates on this? Blocking me from using it entirely. |
Which part is blocking you? Your computer going to sleep and then reconnecting? Does starting the jupyter server yourself (using a remote connection to a localhost) resolve that problem? (I haven't tried to see what happens with jupyter when a computer goes to sleep, not sure if the server stays running or not) We're actively changing the way we connect to remote machines. Part of this will be some form of kernel management. We may also have the same kernel management for local kernels (although not sure how we decide when to kill the kernels). |
Yep, the blocker is that when I have a remote jupyter, when I sleep and wake, I lose all my jupyter state. This means I can't have a persistent session and have to rerun all the cells every time my laptop sleeps. I just tested with a jupyter on localhost and it worked fine. Unfortunately I do a lot of stuff with GPUs, so I have to run on a remote connection. Really appreciate your work here. Love VSCode!! |
Remote kernels should be left running though. If you're using notebooks (and not the interactive window), it should reconnect to the original kernel when you reopen the notebook. Unless you mean remote in the fact that you're using SSH (then the jupyter connection is actually local because it's started on the SSH machine next to where our extension is running). Using SSH would require us to support not shutting down local kernels as well. |
I'm not sure what the interactive window is. I use The kernel does continue to run on my remote machine. I connect to it using HTTPS over VPN. For some reason VSCode can't reconnect to it. Maybe it'd work better if I used |
If you close the notebook and reopen it, does it reconnect? There's no logic for handling sleep (not sure VS code even has an API to tell us about that). However when reopening a notebook we attempt to reconnect to the original kernel. Or at least we should. |
Not sure what eternal-terminal port forward is. We don't need the server URI to be localhost. It should just work as long as you're connecting through the 'Specify local or remote Jupyter server for connections' |
I am not using jupyter or python extensions in VSCode and I have the exact same issue. All my extensions are Javascript and React related. Steps to reproduce are mostly identical.
I have to kill my VPN connection and reconnect new to get VSCode to connect to any SSH host. I'm mostly just supplying further "evidence" to help out. A solution would be great but I've decided it's just part of my job description now. shrug Version: 1.51.1 |
@michaelsanchez-pingidentity I believe you are encountering a separate issue pertaining to the Remote-SSH extension. You might like to check out the Remote-SSH output tab in VSCode when trying to reconnect and see what the logs say, and please do consider filing a bug on their repo so their team can assist you. |
I believe it tries to reconnect after sleep and then gets |
I mentioned this in a separate bug (#1378 (comment)) but its relevant here: it seems extremely weird for the notebook session management to be tied to when the UI is unloaded/reloaded. To be explicit, I here refer to how vscode manages the "local" juptyer servers that it spins up on its own, not the management of kernels on external/existing/"remote" servers that the user has started separately. In most other cases, vscode tries really hard to maintain user state: e.g. for the embedded terminal session, if you reload the window, the same terminal session is still present. But if you do that for a notebook session, the kernel is killed and restarted. Ideally, the lifecycle rules for notebook sessions should be the same as for terminal sessions -- i.e. notebook sessions should persist through UI reloads, but be killed when the user explicitly closes the notebook tab or the workspace window (perhaps with an alert). Contra #1378, "kill the kernel when and only when I close the tab/workspace" might be sufficient UI for managing the lifecycle of kernels, at least on vscode's "local" servers. If UI reloads no longer dispose of running notebooks, this would probably also solve the issues everyone raises above, where disconnects over remote-ssh (which can require reloading the UI to resolve if the disconnect has lasted a while) nuke long-running notebook sessions on the remote-ssh host. It's crazy that a jupyter kernel (the "local" kind, auto-started by the vscode-remote extension on the remote machine) would be happy and alive on the remote machine through the whole disconnect, right up until the vscode client manages to reconnect, and then the very first thing the client does as part of the UI reload is to kill the kernel instead of reconnecting to it. This seems like a major misfeature... should I file it as a separate bug, e.g. "notebook kernels should not be disposed of on UI reload" or something? |
It is an interesting idea to keep the kernel around until an explicit close of a tab. Meaning closing VS code wouldn't kill anything. You'd have to explicitly close the notebook while VS code was open. Although this would have to be behind a setting. I would hazard a guess a lot of people that are used to kernels just being cleaned up would be upset if they didn't go away on VS code shutdown. |
I think it would be reasonable to kill the kernels in any circumstance where a terminal session is also killed. So e.g. quitting vscode would reasonably be expected to kill any local jupyter servers that it spun up internally. It would also be reasonable to add a setting where the kernel would be left running when vscode is quit but the workspace window is left open, since restarting vscode could be expected to restore all state. But I don't think that's necessary either -- again, terminal sessions are killed in such cases. The main thing though is that it seems (to me at least) unreasonable for reloading the UI to kill local notebook kernels. That is contrary to how the terminal works, and appears to be the root cause of everyone's network-disconnect woes with notebooks running local to remote-ssh hosts... |
I need to double check but I don't think we (as an extension) can tell the difference between quitting VS code and reloading the UI. AFAIK, the extension host (the process our extension is running in) is shutdown the same each time. We just get our dispose method called. Terminals are handled by VS code itself, so it may be able to treat reload differently. I think we'd need a new API from VS code to distinguish this case. |
Hmm, that is a pickle then! Will the new "native notebook" feature have this limitation too? Or is that part of the core vscode, more like how terminals are handled? If the latter, perhaps just waiting for that to roll out (and filing bugs on it if needed) would be the best path forward long-term. But if this issue will carry over into the native-notebook world, do let me know if it would be helpful to file an explicit bug to track the root issue about losing user state on UI reload... |
Native notebooks will have the same issue. Kernels are controlled by us. I don't think we need a new bug. Maybe just some more visibility for this one. We can ask VS code for the ability to tell when reload happens versus shutdown and then it would be possible to not kill kernels on reload. |
Pretty sure this is the case, they landed some code semi-recently for supporting this I believe: |
Reading through the PR for the VS code issue, gave me an idea. Might be too much work, but we could have a heartbeat in the kernel. Say every 10 minutes or something. If VS code doesn't respond, it kills itself. That should work in the sleep case (well because the kernel will go to sleep too) and would keep the kernel alive for 10 minutes after a shutdown. |
Clever idea! Might not even need a heartbeat per se? Instead of tearing down the Jupiter server directly on ui reload, set an e.g. 10 minute timer in the server process, after which it tears itself down unless the timer is canceled by a reconnect from vscode. Not sure if that’s dramatically simpler than a full heartbeat system, but perhaps? |
Related to this. |
I've recently started using VS code as a Data Scientist and it helps me a lot with autocompletion and UI. From my point of view, it's much better than the Pycharm. Before VS code I usually set up the docker container on the remote host with project environment inside and jupyter notebook listening on some port. This way I can launch GPU training and safely close the notebook. But with VS code I can't close the notebook or interrupt the connection, since the state of the notebook and the training progress will fail, which is a great issue for anyone who is using jupyter for GPU training. I really love VS code UI and hope there is a way to resolve this issue. |
@Serebryanskiy -- IMO the best current workaround is to use a separate jupyter server with vscode, just like you did before. (It's called "Remote Jupyter" in the vscode lingo, to differentiate it from the "Local Jupyter" server that vscode will start for you, but which goes away when you close vscode etc.) Note that with vscode-remote, if you run the jupyter server on the same machine that you're connected to remotely, you connect to your "Remote" Jupyter server on localhost (i.e. local to where vscode-remote is running). To connect to a "Remote" Jupyter server, just click on the "Jupyter Server" button at the lower right of the window and enter the correct URL with token... It's not perfect; there are a few rough edges compared to using the "Local Jupyter" (e.g. #8285 and #7610) but they're getting fixed over time. |
Thanks, this seems to be the best workaround so far. Manually started a Jupyter server on remote machine, connected VSCode to it using "Jupyter Server: Remote" option and verified through Jupyter logs (on remote machine) that VSCode window reload, VPN disconnect or quitting and restarting VSCode doesn't kill the current kernel which means all Jupyter state variables are retained. |
@vpatil131 @zpincus @8enmann @michaelsanchez-pingidentity If anyone is running into any issues with re-connecting to remote jupyter server, please do feel free to comment here and I'll re-open this issue, or please feel free to create a new issue. If on the other hand someone is starting a local kernel, and the connection dies after the computer sleeps, then please upvote or comment on the issue #3998
The issue that would address this is #3998
Here too, everything is local in the context of VS Code, hence #3998 would address this problem Closing this issue for now, as I believe there has been some confusion around what is local vs remote hence we have duplicate issues. |
Maybe related: #822
Bug: Notebook Editor, Interactive Window, Editor cells
Steps to Reproduce:
Error: Cannot execute code, session has been disposed. Source: Python (Extension)
The workaround I use is close the notebook editor and reopen it, but this loses all my cells. Remote server still has the session.
Your Jupyter and/or Python environment
Version: 1.47.0
Commit: d5e9aa0227e057a60c82568bf31c04730dc15dcd
Date: 2020-07-09T08:01:54.115Z (2 days ago)
Electron: 7.3.2
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Darwin x64 19.5.0
Developer Tools Console Output
Error Python Extension: 2020-07-11 21:30:39: [Error: Kernel is dead at f._sendKernelShellControl (/Users/ben/.vscode/extensions/ms-python.python-2020.6.91350/out/client/node_modules/@jupyterlab/services.js:3:510258) at f.sendShellMessage (/Users/ben/.vscode/extensions/ms-python.python-2020.6.91350/out/client/node_modules/@jupyterlab/services.js:3:510027) at f.requestExecute (/Users/ben/.vscode/extensions/ms-python.python-2020.6.91350/out/client/node_modules/@jupyterlab/services.js:3:512579) at _.requestExecute (/Users/ben/.vscode/extensions/ms-python.python-2020.6.91350/out/client/extension.js:1:535559) at _.requestExecute (/Users/ben/.vscode/extensions/ms-python.python-2020.6.91350/out/client/extension.js:48:460661) at f.P.generateRequest (/Users/ben/.vscode/extensions/ms-python.python-2020.6.91350/out/client/extension.js:48:436320) at f.P.handleCodeRequest (/Users/ben/.vscode/extensions/ms-python.python-2020.6.91350/out/client/extension.js:48:437313) at /Users/ben/.vscode/extensions/ms-python.python-2020.6.91350/out/client/extension.js:48:450604 at runMicrotasks () at processTicksAndRejections (internal/process/task_queues.js:85:5)]
t.log @ workbench.desktop.main.js:sourcemap:266
workbench.desktop.main.js:sourcemap:2947 Error: Cannot execute code, session has been disposed.
Microsoft Data Science for VS Code Engineering Team: @rchiodo, @IanMatthewHuff, @DavidKutu, @DonJayamanne, @greazer, @joyceerhl
The text was updated successfully, but these errors were encountered: