Skip to content

coder ssh: Coder Connect path has no dial timeout, no health check, no tailnet fallback #24006

Closed

Description

@EhabY

coder ssh --stdio via the Coder Connect path has no dial timeout, no connection health monitoring, and no fallback to tailnet when the tunnel is broken. This causes VS Code SSH reconnection to hang for ~55 minutes and then fail permanently after laptop sleep.

Environment

  • macOS (Apple Silicon), VS Code 1.113.0, Remote SSH 0.123.2026033115 (pre-release)
  • Coder Connect active (workspace reachable via fd60: IPv6 prefix)

What happened

The connection dropped several times over a few hours. Each time, VS Code reconnected in 3-8 seconds. Two of the drops showed "Connection closed by remote host" (workspace side actively closed); the others were silent. This instability needs workspace-side logs to diagnose.

On the fatal attempt, the Coder Connect tunnel was broken but DNS still resolved:

t+0s     SSH spawns coder ssh --stdio as ProxyCommand
t+2s     coder ssh resolves workspace, ExistsViaCoderConnect() does DNS lookup for fd60:... → resolves → true
         Commits to Coder Connect path, calls runCoderConnectStdio()
         net.Dialer{}.DialContext("tcp", "fd60:...:22") — no timeout set
         ... TCP dial hangs for 55 MINUTES (macOS default TCP timeout) ...
t+55m    macOS TCP stack: "connect: operation timed out", coder ssh exits
         SSH process dies, VS Code attempts reconnection but the session is already lost
         → "Reload Window"

The laptop was put to sleep during the hang. When it woke the next morning, the stale TCP timeout error was already waiting.

Root cause

1. ExistsViaCoderConnect is DNS-only

func ExistsViaCoderConnect(ctx context.Context, hostname string) (bool, error) {
    ips, err := resolver.LookupIP(ctx, "ip6", hostname)
    // Only checks: does the hostname resolve to a fd60: prefix address?
    // Does NOT verify the address is actually reachable.
}

A broken tunnel with working DNS causes coder ssh to commit to the Coder Connect path with no way to fall back.

2. runCoderConnectStdio has no dial timeout

func runCoderConnectStdio(ctx context.Context, addr string, ...) error {
    dialer := testOrDefaultDialer(ctx)  // &net.Dialer{} — zero timeout
    conn, err := dialer.DialContext(ctx, "tcp", addr)
    if err != nil {
        return xerrors.Errorf("dial coder connect host: %w", err)  // fatal, no retry
    }
    agentssh.Bicopy(ctx, conn, &StdioRwc{...})  // bare io.Copy, no health check
    return nil
}

No Timeout on the dialer, so the only limit is the OS TCP stack (~55 min on macOS). On failure, coder ssh exits with no retry and no fallback to tailnet.

3. No health monitoring on Coder Connect path

Coder Connect path Tailnet path
Dial timeout None (OS default, ~55 min macOS) Context-based
Health check None setStatsCallback(): pings every 3s, exits after 1 min of failures
Workspace monitoring None watchAndClose(): watches workspace lifecycle via SSE
Reconnection None Tailnet controller retries with backoff (50ms-10s)
Fallback None DERP relay fallback if P2P fails

4. No tailnet fallback

The Coder Connect path is a hard return (cli/ssh.go:387):

if exists {
    return runCoderConnectStdio(...)  // if this fails, coder ssh exits
}
// tailnet path below is unreachable

Suggested fixes

  1. Add a dial timeout. Wrap the Coder Connect attempt in a 30s context timeout so it fails fast instead of hanging for 55 minutes.
  2. Fall back to tailnet on Coder Connect failure. If runCoderConnectStdio errors, fall through to the DialAgent tailnet path instead of exiting.
  3. Add health monitoring. TCP keepalive or a periodic check similar to the tailnet path's setStatsCallback. Without this, a mid-session tunnel death is only detected when io.Copy returns (very slow on half-open TCP).
  4. Consider a reachability check in ExistsViaCoderConnect. A quick TCP connect (5s timeout) before committing would catch the broken-tunnel-with-valid-DNS case upfront.

Fixes 1-2 would also be partially covered by a general retry loop in coder ssh (see ENG-2345).

Activity

  1. self-assigned this
    on Apr 3, 2026
  2. spikecurtis commented on Apr 6, 2026

    @spikecurtis
    Collaborator

    I agree that we should have a dial timeout. The other stuff, I'm not convinced.

    Like, if Coder Connect is broken for 55min, shouldn't we have some way to complain to the user about so they can fix it?

    Falling back to in-process tunnel may seem like a friendly thing to do, but it masks an issue with the user's setup. They might go on thinking that Coder Connect is working when it is not. In the meantime, they get worse performance.

    Also, I don't agree that we should be doing any sort of health monitoring. VSCode Remote protocol already does its own health monitoring of the connection.

  3. EhabY commented on Apr 6, 2026

    @EhabY
    CollaboratorAuthor

    Also, I don't agree that we should be doing any sort of health monitoring. VSCode Remote protocol already does its own health monitoring of the connection.

    The issue here is that this operates on a different layer entirely. If VS Code sees an unrecoverable error then it will just panic and restart the window which is the root issue. What we need from here that is crucial for this not to happen is adding the dial timeout and the fallback to tailnet, if this is undesirable then yes we'd have to live with this hard failure (unless we wrap the ProxyCommand with a retry script on the client side but that's also very iffy)

    Also should we just rely on the DNS resolution (ExistsViaCoderConnect)?

  4. EhabY commented on Apr 6, 2026

    @EhabY
    CollaboratorAuthor

    Actually maybe with #24010 we do not need the fallback anyway and we would fail if connection through Coder Connect couldn't be established. The dial timeout can help make this work by retrying in 30s instead of just freezing (waiting for the OS timeout)

  5. added a commit that references this issue on Apr 8, 2026
    027c222
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions