joelspadin / vscode-remote-x11

Visual Studio Code extension that sets the DISPLAY environment variable in remote workspaces
39 stars 9 forks source link

(Provide command to) reconnect (without reloading VS Code) #42

Closed bersbersbers closed 3 years ago

bersbersbers commented 3 years ago

I seem to have issues with vscode-remote-x11 reinstantiating the background SSH connection after my VPN connection breaks down (12h-disconnect, for example). I am still debugging this, but both for debugging and for handling cases where the remote session is closed for other reasons (see below), a command to reconnect Remote X11 would be very handy.

This is what I get when I deliberately kill the sshd process belonging to Remote X11:

Connecting to user@IP port 22
Connection ready. Setting up display...
Echo display command is: bash -c "echo DISPLAY=$DISPLAY"
----- Begin output from host -----

bash -c "echo DISPLAY=$DISPLAY"
[09:54:12] user@host:~$ bash -c "echo DISPLAY=$DISPLAY"
DISPLAY=localhost:10.0

----- End output from host -----
Display ready: localhost:10.0
x11 accept: ::1
x11 accept: ::1
x11 accept: ::1
x11 accept: ::1
x11 accept: ::1
x11 accept: ::1
x11 accept: ::1
Connection closed.

I would expect Remote X11 to retry the connection by itself in such as case.

joelspadin commented 3 years ago

When I lose connection, I usually get a message from the remote extension itself saying it's retrying the connection, and after a while it will give up and offer to reload the window. Do you get the same thing when this happens, and if so is it automatically reconnecting?

If so, there might be some event I can listen to for knowing when to retry the connection. Otherwise a manual command to restart the connection shouldn't be hard to add, since I already send a message to restart the connection whenever you change SSH settings.

bersbersbers commented 3 years ago

When I lose connection, I usually get a message from the remote extension itself saying it's retrying the connection, and after a while it will give up and offer to reload the window. Do you get the same thing when this happens, and if so is it automatically reconnecting?

Yes, I observe the same thing essentially. Automatic reconnection sometimes works if VPN reconnects fast enough (and I don't remember if I have an X11 problem then), and sometimes doesn't (in which case a VS Code reload fixes everything).

But I observed another X11-only (apparently) disconnect yesterday, where the X11 connection stopped working while my remote connection was working fine otherwise. That was pretty exactly 3h after connecting, so maybe there is a timeout involved. I'll observe this further.

If so, there might be some event I can listen to for knowing when to retry the connection.

Yes. In addition, I might consider using an SSH client with automatic reconnect. Do you think I should be able to use KiTTY's klink.exe (essentially PuTTY's plink.exe with reconnect - see https://superuser.com/questions/187293)?

Otherwise a manual command to restart the connection shouldn't be hard to add

That would be great...

since I already send a message to restart the connection whenever you change SSH settings.

... and that sounds like a nice workaround for the short term. Thanks!

joelspadin commented 3 years ago

I'm using https://github.com/mscdex/ssh2 rather than a separate SSH program, so I'd need to implement the reconnect logic myself, unfortunately.

bersbersbers commented 3 years ago

Ah, I see. Well, they may have a solution already :) https://github.com/mscdex/ssh2/issues/491#issuecomment-258031062 and https://github.com/mscdex/ssh2/issues/491#issuecomment-258047263

bersbersbers commented 3 years ago

Thank you, this is working and helpful!