coder / vscode-coder

Open any Coder workspace in VS Code with a single click.
MIT License
68 stars 15 forks source link

VSCode holding open active connections #253

Open nixy opened 6 months ago

nixy commented 6 months ago

I have had a couple of workspaces stay open longer than intended. It seems like VSCode being connected to a workspace in any way count as an active connection even if the connection is idle. This combined with developers never closing VSCode and having laptops that never go to sleep means that my workspaces will never autostop, defeating one of the main advantages of running coder.

I was able to resolve this for SSH connections using ServerAliveInterval 60 and ServerAliveCountMax 0 causing the SSH connection to have a maximum lifetime. I have tried setting these in the Ssh Config section of the Coder Extension's settings but it doesn't seem to have the same effect in VSCode.

Is there a way to establish a maximum lifetime on a connection to a workspace through the VSCode plugin?

Emyrk commented 6 months ago

I have not messed around with ssh settings to accomplish what you are trying to do.

However those ssh settings should be working if this is in your settings.json:

{
    "coder.sshConfig": [
      "ServerAliveInterval 45",
      "ServerAliveCountMax 0"
    ]
}

This will update the settings on ~/.ssh/config on workspace connect. So you need to connect to a workspace in the extension to reload the config.

nixy commented 6 months ago

So that's roughly what my settings.json looks like and I do see the updates to ~/.ssh/config.

# --- START CODER VSCODE ---
Host coder-vscode--*
  ConnectTimeout 0
  LogLevel ERROR
  ProxyCommand "/Users/anmiller/Library/Application Support/Code/User/globalStorage/coder.coder-remote/bin/coder-darwin-amd64" vscodessh --network-info-dir "/Users/anmiller/Library/Application Support/Code/User/globalStorage/coder.coder-remote/net" --log-dir "/Users/anmiller/Library/Application Support/Code/User/globalStorage/coder.coder-remote/log" --session-token-file "/Users/anmiller/Library/Application Support/Code/User/globalStorage/coder.coder-remote/session_token" --url-file "/Users/anmiller/Library/Application Support/Code/User/globalStorage/coder.coder-remote/url" %h
  ServerAliveCountMax 0
  ServerAliveInterval 60
  SetEnv  CODER_SSH_SESSION_TYPE=vscode
  StrictHostKeyChecking no
  UserKnownHostsFile /dev/null
# --- END CODER VSCODE ---

But even with this configuration I am not seeing the behavior I see in a normal SSH connection from the ServerAlive directives.

I'm guessing that there may be something either coder or the VSCode Remote SSH extension is doing that is either ignoring this configuration (seems unlikely) or is doing activity in the background at an interval that is keeping these connections open.

kylecarbs commented 6 months ago

VS Code just reconnects, right? So killing the server connection wouldn't do much.

I believe https://github.com/microsoft/vscode-remote-release/issues/440 would need to be added.

Edit: Accidentally closed 🤦

code-asher commented 6 months ago

Also, I seem to recall VS Code has some kind of 60 second ping so maybe that causes SSH's idle timeout to never trigger. But yeah it would just reconnect anyway. Maybe VS Code has a setting to disable auto-reconnect?

stirby commented 1 month ago

Does this improvement help your case @nixy? https://github.com/coder/vscode-coder/commit/665493841043eb48a8a1a61bf1e2678086513fe2

Also, autostop requirement at a daily interval would prevent workspaces from running overnight due to idle VSCode sessions.