-
Notifications
You must be signed in to change notification settings - Fork 289
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
SSH disconnects when the laptop goes to sleep even for a short time while the native terminal is running #5755
Comments
@roblourens I'm guessing this has to do with the ssh process closing when the computer goes to sleep and when we try to reconnect, we aren't able to within the 5 times so we close the connection? |
It should be trying to reconnect at this point. Please share the log from the Remote-SSH output channel, it should tell us why it failed to reconnect |
@roblourens After I put the laptop lid down and instantly put it up, the password prompt comes, if I do not enter the password and click exit I get the following log. Though, my concern is that vscode should not ask for password again if I instantly open up my lid again (similar to macOS native terminal).
|
Well, the socket might close for some reason in the time that the laptop was asleep. Seems that sometimes ssh in the terminal will survive a brief sleep, sometimes not, same for vscode. Also, we implement our own timeout where once the remote is not reachable for some amount of time, we assume it's disconnected and try to reconnect. So I have to just call this "by design". @alexdima I wonder whether it could be improved for scenarios like this, if we can check the previous socket again after waking from sleep. It's much more smooth if you set up SSH with your passphrase in the ssh agent so you don't need to type anything to connect |
@roblourens The core will invoke the resolver again. You can definitely return the same port again from the resolver if the previous SSH tunnel is still healthy. For example, once it started the server, Remote WSL always returns the same port from the resolver. |
Honestly, I think there should be at least this level of robustness to keep the session alive for cases when the laptop has just gone to sleep. If I set my screen sleep time to 10 minutes the ssh remains active for this long. But if I set my screen sleep to 1 minute the ssh disconnects as soon as the screen goes off even for a few seconds. I appreciate the your efforts in discussing this issue. Thanks! |
We have the ability to test the connection again, but wouldn't it make more sense for the core to do that? |
Doing that in all cases means that in many cases we would waste around 30s (the timeout we have) trying to connect to a possibly broken resolver port. So we always just invoke the resolver which can trivially return the same port if it so wishes. e.g. of what you could do in the SSH resolver (if you want to): class Resolver {
private lastPort: number = 0;
private lastPortReusedTime: number = 0;
public resolve(ctx) {
const shouldReuseLastPort = (
this.lastPort
&& (Date.now() - this.lastPortReusedTime > 5 * 60 * 1000) // the port was not reused within the past 5 minutes
);
if (shouldReuseLastPort /* && tunnel process still alive */) {
// try to reuse the same tunnel, maybe it still works fine
this.lastPortReusedTime = Date.now();
return this.lastPort;
}
this.lastPortReusedTime = 0;
// ...
// this.lastPort = ...
return this.lastPort;
}
} The core calling the resolver gives the most freedom. Resolvers that know that they are really disconnected can recreate the connection, while resolvers which don't know can try to be lucky and return first the old port and only on a subsequent resolve call create a new tunnel. What do you think? |
If we reuse the port, and it turns out to be stuck, will vscode spend 30s trying to connect to it? Because that will happen sometimes. The resolver can also ping the server through the port with a shorter timeout. |
👍 Yes, that is exactly the point I was trying to make. When the core tries to reconnect to a |
@tanhakabir I've been wanting to do an optimization like this. We can ping the |
OK so I have the same symptoms, but a different configuration. In a nutshell, my configuration is like: SSH on mac host to 127.0.0.1 -> Unix socket -> VSOCK -> Linux' guest SSH.
As the connection is performed over VSOCK, it is guaranteed to be stable (no disconnects). I have tested this using both SSH, One thing to note is that the time on the VM momentarily drifts backwards for about 5 seconds before it syncs back to the host time. Also for what its worth, this is a custom hypervisor based on macOS Hypervisor.framework. |
Hi all, the problem on macOS is that Chrome is the one to blame: Chrome will disconnect active WebSocket connection, even the one made locally to Also FWIW, Safari does not do this. Not sure about Windows as I don't have a Windows machine for the time being, but I think on Windows it is not related to the Chrome's problem I mentioned AFAIK. |
Hi @kieferrm @eleanorjboyd @roblourens, apologise beforehand for tagging. However, considering that this is Google Chrome's issue of cutting off WebSocket connection when the laptop is put to standby, I wonder what are your approach in tackling this problem? Are you going to patch the underlying Electron code on the upcoming VSCode to fix this behaviour, or are you going to make this extension be able to persist states between reconnection? |
I wouldn't mess with that, we just need to make sure that we are reconnecting cleanly when waking up again. We haven't had time to look into this though. Thanks for the tip about Chrome though! |
Not exactly related to disconnect-on-sleep issue, but just an UX improvement idea: currently VSCode allows at most 8 reconnect attempts before it gives up and requires window reload, is it possible to set max to 20 attempts for example? Disconnections can be hard to avoid for people on the move, and when it comes to reconnection I observe vastly different behaviour between VPS providers, some of them allow faster reconnection while with others it takes forever, especially when VPN is involved. I guess it all boils down to their routers config and is beyond our control, but to make VSCode more resilient, probably trying reconnecting for a bit longer is sufficient in such scenarios. |
Hi @movy, happy to talk more in depth on this if you create another issue but if you set the max reconnection attempts to |
How to do this any step-by-step guide. I am trying to connect SSH server using VS Code but when my laptop goes to sleep the process that runs stops and the server disconnects again I need to start from first. |
Steps to Reproduce:
The vscode is now disconnected and asks me to reload window. The macOS terminal is still connected to the remote and works perfectly. Is there a way to delay the session time-out time in vscode? It is a bit annoying to reload every time the screen goes off for a minute. I have to increase the sleep duration to tackle this issue.
Does this issue occur when you try this locally?: Yes
Does this issue occur when you try this locally and all extensions are disabled?: Yes
The text was updated successfully, but these errors were encountered: