Skip to content

ExistsViaCoderConnect false positives when Coder Desktop has stale DNS but no working tunnel, causing coder ssh --stdio to hang #26669

Open

Description

@blinkagent

Summary

When Coder Desktop (Coder Connect) is in a broken-but-not-cleaned-up state on the
user's machine — i.e. the NRPT rule and embedded DNS responder are still in place
and answering with addresses inside tailnet.CoderServicePrefix (fd60:627a:a42b::/48),
but the tailnet itself is not actually carrying traffic — coder ssh --stdio is
fooled into taking the Coder Connect direct-dial path and hangs until timeout.

End-user symptom: ssh coder.myworkspace (via the coder config-ssh-generated
ProxyCommand) fails with:

error: dial coder connect host:
  - dial tcp [fd60:627a:a42b:....]:22: connect: operation timed out

…while coder ssh myworkspace (which builds its own tailnet client in-process and
does not consult ExistsViaCoderConnect) works fine against the same workspace
from the same machine.

A reboot (which clears Coder Desktop's residual NRPT rule / Wintun adapter / DNS
state) restores ssh coder.*.

Root cause

ExistsViaCoderConnect
decides whether Coder Connect is "available" purely by doing an IPv6 DNS lookup
and checking whether any returned address falls inside CoderServicePrefix:

ips, err := resolver.LookupIP(ctx, "ip6", hostname)
// ...
for _, ip := range ips {
    if tailnet.CoderServicePrefix.AsNetip().Contains(addr) {
        return true, nil
    }
}

There is no liveness probe of the tunnel itself. As a result, any environment
where the OS resolver still returns a fd60::/48 address — even though the
underlying tunnel is dead — causes coder ssh --stdio (called from the
ProxyCommand coder ssh --stdio --ssh-host-prefix coder. %h) to enter
runCoderConnectStdio, which then tries dial tcp [fd60:…]:22 and blocks
until the OS-level connect timeout.

The function's own doc comment acknowledges the gap:

This doesn't guarantee the workspace is actually reachable, if, for example,
its agent is unhealthy, but rather that Coder Connect knows about the workspace
and advertises the hostname via DNS.

…but the caller in cli/ssh.go treats a true return as sufficient to commit
to the Connect-only path.

Reproduction

  1. On Windows (or macOS) with Coder Desktop installed and Coder Connect previously
    enabled, get the host into a state where the NRPT rule for .coder (or
    equivalent on macOS) and the embedded DNS responder are still present, but the
    tunnel is no longer functional. In practice this seems to happen after:
    • network/VPN flap
    • waking from sleep
    • control-plane DNS briefly failing to resolve, then recovering
  2. Resolve-DnsName myworkspace.coder still returns an fd60:… address.
  3. Run ssh coder.myworkspace via a coder config-ssh-generated config (or an
    equivalent hand-written one using coder ssh --stdio --ssh-host-prefix coder.).
  4. Observe the hang and the dial tcp [fd60:...]:22: connect: operation timed out.
  5. coder ssh myworkspace (no --stdio) succeeds against the same workspace.

Suggested fix

ExistsViaCoderConnect (or its caller in cli/ssh.go) should additionally
confirm the tunnel is actually carrying traffic before committing to the Connect
path. Options, roughly in increasing order of invasiveness:

  1. Fast liveness probe — after the DNS check returns a fd60::/48 address,
    attempt a very short TCP dial (e.g. to the agent API port 4, or to 22)
    with a sub-second timeout. If that fails, treat Connect as unavailable and
    fall through to the non-Connect path.
  2. Local IPC hint from Coder Desktop — have Coder Desktop expose a local
    "tunnel healthy" sentinel (named pipe / UDS / loopback HTTP endpoint, or a
    sentinel hostname that only resolves when the dataplane is live) that the
    CLI can check cheaply.
  3. Tear-down on Coder Desktop side — Coder Desktop should remove its NRPT
    rule / DNS entries when the tunnel becomes unhealthy, so LookupIP returns
    NXDOMAIN and ExistsViaCoderConnect correctly returns false. (Tracked
    separately on the Desktop side as Tray reports Coder Connect as healthy while tunnel/DNS is broken; stale NRPT rule causes downstream tooling to hang or fail coder-desktop-windows#171.)

Option 1 is the smallest, most defensive change here and would prevent the
hang regardless of what Coder Desktop does.

Related

Notes

  • Reported by a user in the field; reboot resolved it, confirming residual
    Coder Desktop / OS-resolver state as the trigger.
  • The ~/.ssh/config produced by coder config-ssh is not at fault — the same
    hang reproduces with any config that routes through coder ssh --stdio.
  • This is independent of the coder agent-name collision class of bug; in the
    observed case the agent was named main.

Created on behalf of @mdanter

Activity

  1. linear-code commented on Jun 24, 2026

    @linear-code
  2. ametel01 commented on Jun 25, 2026

    @ametel01

    I would like to work on this.

    My current plan is to keep ExistsViaCoderConnect as a DNS-advertisement check, then make coder ssh --stdio do a short TCP liveness probe after DNS says Coder Connect exists and before committing to the Coder Connect stdio path. If the probe succeeds, it continues through Coder Connect as today. If the probe fails or times out, it falls back to the normal tailnet dial path instead of surfacing the stale Desktop tunnel failure.

    I am leaning toward probing the agent HTTP API port, workspacesdk.AgentHTTPAPIServerPort / port 4, since that proves the Coder-owned dataplane is alive without depending on SSH behavior. The main thing I would like maintainer direction on is the timeout value, and whether port 4 is the preferred sentinel versus SSH port 22.

  3. ethanndickson commented on Jun 26, 2026

    @ethanndickson
    Member

    I'm not completely sold on the idea of a TCP liveness probe. I think it's important the user knows their Coder Desktop is misbehaving. However, I'm not sure what the correct move forward here is. IMO fixing the underlying cause for the failing connection to workspaces seems preferable. We opted for the DNS check specifically to avoid needing to do some TCP liveness with a timeout.

  4. ametel01 commented on Jun 26, 2026

    @ametel01

    @ethanndickson
    Thanks, that makes sense. I was treating the CLI fallback as a defensive workaround for stale Desktop state, but I agree it can hide that Coder Desktop is unhealthy and adds a timeout-based probe to a path that was intentionally DNS-only.

    I’ll pause the TCP liveness-probe approach. It sounds like the better fix is for Coder Desktop / the VPN tunnel to keep advertised DNS state aligned with dataplane health: if the tunnel cannot carry traffic, Desktop should stop advertising .coder records or mark Connect unhealthy and surface recovery.

    For the CLI side, would you prefer we leave behaviour unchanged for now, or only improve the failure message when the Coder Connect direct dial fails so users know Desktop is misbehaving and can restart/toggle Connect or use --force-new-tunnel?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions