#22864·coder

Agent killed by wgengine watchdog timeout on Ping during network disruption

Author: mafredriCreated Mar 9, 2026Updated Oct 1, 2026
Labelsnetworkingneeds-triagebuggithub-sync

This description was restructured by Coder Agents on behalf of Mathias Fredriksson. The previous description is in the collapsed section at the bottom.

Problem

The workspace agent wraps its Tailscale engine in a watchdog (tailnet/conn.go:243, coder/tailscale wgengine/watchdog.go). If any engine call runs longer than 45 seconds, the watchdog writes a goroutine dump to stderr and calls log.Fatalf. The agent process exits with code 1. If the agent is PID 1 (reaper mode), the container stops with it.

Coder does not restart the agent. Whether it comes back depends on how the template runs it. In coder/coder#27840, Kubernetes restarted the container 7 seconds later. The docker example template sets no restart policy, so its container stays stopped. Until the agent is back, every connection to the workspace through the agent fails: SSH, IDEs, port forwarding and apps.

How to recognize it

These lines go to the agent's stderr (for example the container log), not to coder-agent.log:

wgengine watchdog in-flight:
in-flight[N]: name=UpdateStatus duration=1m2s start=...
wgengine: watchdog timeout on UpdateStatus

Reports

Date Version Call that timed out Source
2026-03-09 main f07e26690 Ping (4 calls) Original report, collapsed below
2026-03-31 main, late March build UpdateStatus Internal dev.coder.com workspace; log held by Mathias Fredriksson
2026-08-04 v2.35.2 UpdateStatus, about once a day on one workspace coder/coder#27840
2026-08-07 v2.29.12 UpdateStatus Customer report, 4 times in 7 days across 3 users; one dump and log attached in Linear
2026-09-29 v2.33.7 None in the support bundle Customer report; the bundle was captured outside any episode

A 2026-08-04 comment on this issue (v2.35.2) reports a different symptom: the agent stays up but stops reading its DERP connection for 15 to 30 minutes. It has no dump, so it is not confirmed to be the same bug.

coder/coder-desktop-windows#177 shares only the watchdog. Its dump shows Reconfig waiting in Windows DNS setup, not on magicsock locks.

What the dumps show

Two watchdog dumps were analyzed: the v2.29.12 dump and the 2026-03-31 dump. The 2026-03-09 dump was not available.

  • In both, one goroutine held the magicsock connection lock (Conn.mu) while waiting for a per-peer lock (endpoint.mu), and many goroutines queued behind Conn.mu. The holder differed. In the v2.29.12 dump it was the UDP receive path handling a peer discovery message (handleDiscoMessage → addCandidateEndpoint), and the timed-out UpdateStatus was queued behind it. In the 2026-03-31 dump the holder was the timed-out UpdateStatus itself (populatePeerStatus).
  • The goroutines holding endpoint.mu (heartbeat and ping-timeout callbacks) were runnable, not blocked on a lock or I/O. Neither dump has a lock cycle.
  • In the same minute the whole agent process ran slowly. Collecting the goroutine dump took about 8 to 20 seconds; a dump of that size normally takes milliseconds. Log lines were written up to 38 seconds after their timestamps. Work that does not use magicsock also timed out: localhost app health checks, docker ps, and writes to coderd.
  • Neither log shows network changes (LinkChange, rebind, interface churn) in the 25 minutes before the stall. The 2026-03-09 report describes Docker network churn before its crash.

This supports a process-wide stall as the precondition, with the Conn.mu pile-up following from it. It does not rule out the pile-up adding to the delay. What stalled the process (CPU throttling, memory pressure, node load) is unknown, because no CPU or memory metrics exist for any crash.

Current state

  • The watchdog is unchanged on main (d9c13dc06d) and in every release from v2.29.12 through v2.37.3, the newest tag: 45 seconds, then log.Fatalf.
  • The agent calls UpdateStatus and one Ping per peer on every stats report (deployment default every 30 seconds).
  • Setting TS_DEBUG_DISABLE_WATCHDOG=true in the agent's environment disables the watchdog (coder/tailscale wgengine/watchdog.go:34). Coder never sets it. Its effect on these crashes is untested.
  • #22868 (serialize stats pings) and #22869 (keep stats and metadata errors from restarting the agent's API routines) were closed unmerged by the stale bot on 2026-03-20.
  • coder/tailscale#129 (recover from a watchdog timeout instead of exiting) is open with no reviews. Its coder/coder companion #27766 was closed unmerged.
  • Upstream Tailscale removed the watchdog in May 2026 (tailscale/tailscale#19763). The fork is based on upstream 1.47.0.
  • #9119 (2023) was the same watchdog exit on an overloaded VM. It was closed as a duplicate of #8517, which led to opt-in process priority settings (CODER_PROC_PRIO_MGMT).

Not explored

  • The 2026-03-09 log, goroutine dump and surviving-workspace log: not found.
  • The coder/coder#27840 dump, offered privately by the reporter.
  • The goroutine dump that the 2026-08-04 no-crash comment offered to capture during a later episode.
  • The other three occurrences in the v2.29.12 customer report.
  • The source of the v2.33.7 customer's figures (about 778 disconnects in 48 hours, a load test that reproduced it).
  • CPU, memory and throttling metrics for any crash.
Previous description (2026-03-09, edited 2026-09-29; customer names removed)

Known errors in this text: #22868 and #22869 were never merged. coder/coder#27840 is a watchdog exit, not the no-crash stall. Not every deployment restarts the container. The v2.29.12 crash had 2 peers, which weakens the peer-count hypothesis. The reading of 19 discoPingTimeout waiters as about 95 seconds of unreachability is unverified.

What happened

A workspace agent was killed by the tailscale wgengine watchdog timer. Four concurrent Ping calls, initiated by the stats reporter to measure peer latency, were blocked for ~97 seconds waiting on magicsock.(*Conn).mu, exceeding the watchdog's 45-second hard timeout. The watchdog calls log.Fatalf (i.e. os.Exit(1)), immediately terminating the process. The reaper parent (PID 1) propagated exit code 1.

2026/03/09 20:41:46 wgengine watchdog in-flight:
in-flight[630]: name=Ping duration=1m38.188s start=2026-03-09T20:40:08.425951565Z
in-flight[631]: name=Ping duration=1m37.504s start=2026-03-09T20:40:09.110417818Z
in-flight[632]: name=Ping duration=1m37.338s start=2026-03-09T20:40:09.276552228Z
in-flight[633]: name=Ping duration=1m36.479s start=2026-03-09T20:40:10.135775422Z
2026/03/09 20:41:46 wgengine: watchdog timeout on Ping
2026-03-09 20:41:46.640 [info]  reaper: child process exited, propagating exit code  exit_code=1

User Impact

When this bug fires, the workspace agent stops working for the length of the outage. It crashes outright, or in a newer variant, it goes unresponsive without crashing. Every active SSH session, IDE connection, and forwarded app for that workspace drops until the agent recovers or Kubernetes restarts the container. The user loses the session and must reconnect, or wait out the stall.

Four reports confirm this across separate organizations and Coder versions, tracked across three linked tickets plus this one.

This ticket, PLAT-35, mirrors the GitHub report at https://github.com/coder/coder/issues/22864 through the sync label. It carries two customer reports directly. One customer, through a support ticket, reported the failure 4 times in 7 days, across 3 users, on the UpdateStatus call. Another organization reported around 778 disconnect events in 48 hours on its own deployment, on version 2.33.7.

PLAT-440 is a separate ticket for the same lock chain, on version 2.35.2. There, the agent goes unresponsive for 15 to 30 minutes instead of crashing, so the user sees a stall rather than a restart.

A fourth report sits in a comment on the GitHub issue itself, from a user on version 2.29.12, again blocked in UpdateStatus. Together these four reports span versions 2.29 through 2.35.

PLAT-398 is also linked to this ticket, but it is a different bug: a resources-monitor setup failure that blocks the agent's API connection permanently. Treat it as related context, not the same failure.

Timeline

The log covers ~27 minutes (20:15:01 to 20:41:46, 10000 lines). The agent was fully healthy for the first 15 minutes: zero warnings, all app health checks passing, DERP connected to region 10013 with stable ~17ms latency, metadata completing promptly, WireGuard keepalives normal.

Early warning signs (20:18 to 20:30)

Intermittent DERP latency spikes begin appearing in otherwise-healthy netcheck reports:

Time Region Latency Normal
20:18:51 Johannesburg (10018) 333ms ~190ms
20:20:23 Sydney (10015) 720ms ~258ms
20:24:15 Johannesburg (10018) 575ms ~190ms
20:29:12 Johannesburg (10018) 597ms ~190ms
20:29:36 Sydney (10015) 737ms ~258ms

Everything else remains normal during this period. Health checks pass, metadata succeeds, and the primary DERP region (Paris, 10013) stays at ~17ms.

Docker network interface churn begins (20:30:51)

Starting at 20:30:51, the wgmonitor detects a series of network interface destructions. Eight veth interfaces (outif 41 to 55, odd-numbered, consistent with Docker veth pairs) are deleted in sequence over the next 5 minutes:

20:30:57  RTM_DELROUTE outif=41
20:31:32  RTM_DELROUTE outif=43
20:32:02  RTM_DELROUTE outif=45
20:32:24  RTM_DELROUTE outif=47
20:34:54  RTM_DELROUTE outif=49
20:35:32  RTM_DELROUTE outif=51
20:35:37  RTM_DELROUTE outif=53
20:35:42  RTM_DELROUTE outif=55

Each triggers LinkChange: minor events and netcheck re-probes. The netcheck interval, previously steady at ~22 seconds, collapses to bursts of 0 to 5 second intervals as the probes pile up.

System degradation (20:30:37 to 20:34)

The interface churn coincides with broader system pressure:

  • 20:30:37: First warning: WaitDelay expired before I/O complete on a child process.
  • 20:31:18: cpu_usage and ram_usage metadata collection start timing out (1s timeout).
  • 20:31:23: DERP latency checks to all regions hit context deadline exceeded.
  • 20:31:29: First derp=0 netcheck report (no DERP relay reachable). It recovers to derp=10013 one second later at 20:31:30.
  • 20:31:26 to 20:31:29: App health checks (code-server, filebrowser, mux) fail with context canceled.

First API connection death (20:34:07)

The TCP connection to coderd (172.20.0.18:38850 → 34.67.63.199:443) breaks:

[ERR] yamux: Failed to write header: ... write: broken pipe

All dRPC streams fail, all agent API routines tear down, all tailnet peers are marked lost. The agent reconnects within ~1 second (connecting to coderd at 20:34:07.676, all routines restarted by 20:34:08).

At 20:34:28, the wgmonitor reports time jumped (probably wake from sleep); synthesizing major change event, triggering a LinkChange: major, rebinding with a full DERP rebind.

The tailnet (WireGuard network) is not torn down during API reconnection. The same tailnet.Conn and watchdog-wrapped wgengine persist, continuing to accumulate reconnection-related goroutines.

Continued instability (20:34 to 20:40)

After reconnection, the system remains degraded:

  • Metadata collection (cpu_usage, ram_usage) times out repeatedly.
  • docker ps / docker inspect commands are killed by the OS or hit context deadline exceeded.
  • App health checks fail continuously. By 20:39:10, code-server and filebrowser flip to now_unhealthy=true.
  • Netcheck oscillates between derp=0 and derp=10013. At 20:37:24, even UDP probes fail entirely (udp=false v4=false).
  • Docker veth deletions continue (outif 49 to 55 between 20:34:54 and 20:35:42).

Watchdog kill (20:40:08 to 20:41:46)

  1. 20:40:08 to 20:40:10: The stats reporter's Collect() fires 4 Ping calls (one per peer) to measure latency. These enter the watchdog-wrapped wgengine.Ping().
  2. 20:40:44: The second API connection dies (yamux: keepalive failed: i/o deadline reached).
  3. 20:40:55: dRPC writes start timing out (connection write timeout).
  4. 20:41:46: Everything collapses. The second API connection breaks (broken pipe). The wgmonitor fires another time jumped; synthesizing major change event, triggering a rebind. WireGuard peers flood handshake initiations, disco pings, and STUN probes, all contending for magicsock.(*Conn).mu.
  5. The 4 Ping calls have been blocked for ~97 seconds. The watchdog fires log.Fatalf("wgengine: watchdog timeout on Ping"), killing the process.

Goroutine dump analysis

The watchdog dumped 605 goroutines at crash time. Detailed analysis of the dump reveals the specific lock chain that caused the 97-second stall.

Who holds Conn.mu

The single goroutine holding Conn.mu is the DERP RoutineReceiveIncoming goroutine. It followed the standard DERP receive path and is now stuck waiting for a per-peer endpoint.mu:

RoutineReceiveIncoming → receiveDERP → processDERPReadResult
  → handleDiscoMessage       (acquires c.mu at magicsock.go:1431, deferred unlock)
    → handlePingLocked       (called with c.mu held)
      → addCandidateEndpoint (tries de.mu.Lock at endpoint.go:843 → BLOCKED)

This goroutine correctly follows the documented lock ordering (Conn.mu then endpoint.mu). It cannot release Conn.mu until addCandidateEndpoint returns, and that cannot return until it acquires endpoint.mu.

Who holds endpoint.mu

The endpoint.mu for the target peer is held by either a heartbeat goroutine or a RoutineSequentialSender goroutine, both inside sendDiscoPingsLocked. The dump catches them mid-goroutine-creation (go sendDiscoPing(...), go enqueueCallMeMaybe(...)), meaning they are actively executing, not blocked.

Those spawned goroutines themselves need Conn.mu (via sendDiscoMessage and enqueueCallMeMaybe), but since they are launched with go, the spawner is not blocked on them. In theory, endpoint.mu should be released in microseconds once the spawner finishes and returns.

The convoy effect

The reason this persists for 97 seconds despite no classical deadlock cycle is visible in the accumulated discoPingTimeout callbacks: 19 goroutines are blocked waiting for endpoint.mu in discoPingTimeout (endpoint.go:525). Since each disco ping times out after ~5 seconds, 19 timeouts implies the peer has been unreachable for roughly 95 seconds, consistent with the 97-second watchdog duration.

Each heartbeat cycle (every ~2 seconds) acquires endpoint.mu, iterates endpoint state, and spawns disco pings. Each time the DERP receiver tries to process an incoming disco ping for the same peer, it holds Conn.mu and waits for endpoint.mu. This creates a convoy: 47 goroutines needing Conn.mu pile up behind a single DERP receiver that is repeatedly waiting for a heavily-contested endpoint.mu.

Full Conn.mu waiter breakdown

Count Blocked in Path
26 sendDiscoMessage (line 1344) disco ping sends
5 enqueueCallMeMaybe (line 1695) spawned from sendDiscoPingsLocked
5 ReSTUN (line 2269) spawned from enqueueCallMeMaybe
4 Ping (line 798) the watchdog victims (stats reporter)
6 derpWriteChanOfAddr (line 268) data packet sends needing DERP channel lookup
1 receiveIP (line 1296) IPv4 RoutineReceiveIncoming

Plus the 1 goroutine that holds Conn.mu (the DERP receiver blocked on endpoint.mu). Total: ~48 goroutines in the Conn.mu contention chain.

What is NOT involved

  • gvisor TCP cleanup goroutines (18 goroutines in timeWaitTimerExpired paths): These are blocked on gvisor-internal mutexes (cleanupEndpointsMutex, transportEndpointsRWMutex). They have no lock dependency on magicsock.Conn.mu. They represent independent contention from many TCP connections hitting TIME_WAIT simultaneously.
  • WireGuard worker pools (288 goroutines across RoutineDecryption/Handshake/Encryption): Idle, waiting on channels for work. Normal.
  • yamux/dRPC goroutines: Idle on their control connections, waiting for data. Not holding any relevant resources.

Assessment

This is not a classical ABBA deadlock. The lock ordering (Conn.mu then endpoint.mu) is technically respected. The problem is a convoy/livelock: when a peer is unreachable, disco ping timeouts and heartbeat cycles repeatedly contest endpoint.mu for that peer, and whenever the DERP receiver processes an incoming disco message for that same peer, it holds the global Conn.mu while waiting for the per-peer endpoint.mu. Everything else that needs Conn.mu (sending packets, pings, STUN, DERP lookups) stalls for the duration.

Comparison with surviving workspace

A second workspace on the same Coder deployment, running on the same infrastructure during the same time window, provides a control case. Its log (w.log, 1223 lines) covers 20:20:03 to 20:32:02 and ends with the workspace still fully healthy. It shares one peer ([PP902]) with the crashed workspace.

Same DERP latency spikes

Both workspaces see the same intermittent DERP latency spikes to Sydney and Johannesburg at overlapping times:

Time (surviving) Region Latency Nearest match (crashed)
20:20:51 Sydney (10015) 507ms 20:20:23: 720ms
20:22:31 Sydney (10015) 731ms (none nearby)
20:25:09 Johannesburg (10018) 599ms 20:24:15: 575ms
20:28:37 Sydney (10015) 502ms (none nearby)
20:29:19 Sydney (10015) 723ms 20:29:36: 737ms
20:31:11 Sydney (10015) 721ms (none nearby)
20:32:02 Johannesburg (10018) 596ms (none nearby, last entry)

This confirms the DERP latency spikes are infrastructure-level, not specific to the crashed workspace.

Same Docker veth churn, smaller scale

The surviving workspace also experiences Docker veth interface deletions: 4 interfaces (outif 225, 227, 229, 231) removed between 20:29:18 and 20:30:22. The crashed workspace saw 8 interfaces (outif 41 to 55) deleted starting slightly later at 20:30:51 and continuing through 20:35:42.

The surviving workspace produced 12 LinkChange events during its churn window (all minor, confined to 20:29:18 to 20:30:22). The crashed workspace produced 25, including a major change with full DERP rebind at 20:34:28. Its netcheck interval, previously steady at ~22 seconds, briefly compressed to 0 to 5 second bursts during the veth deletions (20:29:18 to 20:30:22), then recovered to ~17 seconds by 20:30:48. The crashed workspace never recovered its netcheck cadence.

Three dRPC EOF errors appeared at 20:29:07, likely related to the veth churn, but caused no further impact.

Zero errors

The surviving workspace log contains zero errors and zero warnings. DERP connectivity never dropped to 0. There was no API connection loss, no yamux failures, no metadata timeouts, no "time jumped" events. By contrast, the crashed workspace was already showing metadata timeouts and WaitDelay expired warnings by 20:30:37 and was dead by 20:41:46.

Peer count difference

T