Repository navigation
Description
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
- 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
Resolve-DnsName myworkspace.coderstill returns anfd60:…address.- Run
ssh coder.myworkspacevia acoder config-ssh-generated config (or an
equivalent hand-written one usingcoder ssh --stdio --ssh-host-prefix coder.). - Observe the hang and the
dial tcp [fd60:...]:22: connect: operation timed out. 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:
- Fast liveness probe — after the DNS check returns a
fd60::/48address,
attempt a very short TCP dial (e.g. to the agent API port4, or to22)
with a sub-second timeout. If that fails, treat Connect as unavailable and
fall through to the non-Connect path. - 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. - Tear-down on Coder Desktop side — Coder Desktop should remove its NRPT
rule / DNS entries when the tunnel becomes unhealthy, soLookupIPreturns
NXDOMAIN andExistsViaCoderConnectcorrectly returnsfalse. (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
- 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 — companion Desktop-side issue: "Tray reports
Coder Connect as healthy while tunnel/DNS is broken; stale NRPT rule causes
downstream tooling to hang or fail." - [bug] Coder Connect on Windows: DNS publishing silently fails — workspace lookups return empty answers despite Connect being on coder-desktop-windows#170 — "DNS publishing silently fails — workspace
lookups return empty answers despite Connect being on" (the inverse failure
mode of the same underlying state-management gap). - coder/coder-desktop-windows#149 — "Not connected after waking from sleep"
(one of the triggers for the broken-but-not-cleaned-up state).
Notes
- Reported by a user in the field; reboot resolved it, confirming residual
Coder Desktop / OS-resolver state as the trigger. - The
~/.ssh/configproduced bycoder config-sshis not at fault — the same
hang reproduces with any config that routes throughcoder ssh --stdio. - This is independent of the
coderagent-name collision class of bug; in the
observed case the agent was namedmain.
Created on behalf of @mdanter
Activity
linear-code commentedon Jun 24, 2026
ENG-2957
ametel01 commentedon Jun 25, 2026
I would like to work on this.
My current plan is to keep
ExistsViaCoderConnectas a DNS-advertisement check, then makecoder ssh --stdiodo 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.ethanndickson commentedon Jun 26, 2026
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.
ametel01 commentedon Jun 26, 2026
@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?
docs: add Coder Desktop stale-tunnel recovery and improve macOS log c…