Skip to content

Coder Connect tunnel not re-STUN'd on system wake; dead for minutes after macOS sleep #26736

Closed

Description

@EhabY

Summary

After a macOS client sleeps and wakes, the Coder Connect tunnel to a workspace can stay unusable for several minutes. New dials fail with dial tcp [fd60:...]:22: i/o timeout until magicsock's periodic re-STUN re-homes the path on its own. VS Code Remote-SSH's resolver times out in that window and surfaces as "Reload Window" / UnparsableOutput.

Evidence (support bundle, macOS arm64, Coder Connect path)

  • Control plane healthy throughout (workspace/agent API calls return 200).
  • coder ssh proxy log: dial coder connect host "...:22" over tcp: i/o timeout on retries. The process was frozen mid-dial during sleep (~5 min wall-clock gap with no logs) and failed on wake.
  • By bundle-generation time the same path was direct p2p at 9 ms, so it recovered without intervention.

Root cause (coder/coder f66df86, coder/tailscale b7c5fc6)

Auto-recovery is wired and active:

  • wgengine/userspace.go:427 starts the netmon (e.netMon.Start(), unconditional).
  • :307 registers a change callback to linkChange().
  • linkChange() (:1126) calls magicConn.Rebind() on a major change and magicConn.ReSTUN() always.

This only fires on a netmon link-change event. macOS wake from a short same-network sleep often produces no such event, so linkChange never runs and recovery falls back to magicsock's slow periodic re-STUN. The daemon has no proactive wake trigger (vpn/tunnel.go:672's only sleep-aware code just reconciles deleted workspaces after reconnect).

Proposed fix

Force a rebind and re-STUN on wake:

  1. Expose on tailnet.Conn:
    func (c *Conn) Rebind() {
        c.magicConn.Rebind()
        c.magicConn.ReSTUN("wake")
    }
  2. Add a ManagerMessage_Wake case to vpn/tunnel.go handleRPC that calls conn.Rebind().
  3. Coder Desktop (macOS) subscribes to NSWorkspace.didWakeNotification (or IORegisterForSystemPower) and sends the RPC on wake.

This is an event-driven kick on a known OS event, not a health check. It forces re-discovery and never tears down a live tunnel.

Confirming

In Coder Desktop daemon net.wgengine logs around a wake, check for LinkChange: major, rebinding. Its absence at wake time confirms netmon is not firing.

Activity

  1. linear-code commented on Jun 26, 2026

    @linear-code
  2. self-assigned this
    on Jun 26, 2026
  3. EhabY commented on Jun 28, 2026

    @EhabY
    CollaboratorAuthor

    Related: the Remote-SSH side of the same wake failure is microsoft/vscode-remote-release#11720 (local-server delayShutdown timer fires retroactively on macOS wake -> permanent UnparsableOutput).

    They're complementary, and re-STUN here does not fix the sleep case alone: on wake the Remote-SSH timer fires at t≈0 (already-expired deadline) and the resolve is declared permanently dead before the re-STUN'd tunnel becomes dialable. Both are needed — #11720 keeps the resolve alive across the wake, and #26736 gets the tunnel dialable inside coder ssh's ~70s retry budget so the next dial succeeds. #26736 still independently helps the non-sleep cases (DERP flaps, network switches).

  4. added a commit that references this issue on Jul 13, 2026
    e11147e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions