Commit Graph
6 Commits
Author SHA1 Message Date
Bobby Ho 603dd420d1 feat: add ServerTailnet logs and metrics for unreachable agents (#30133)
Add default-level metrics and warn-level diagnostics to investigate
ServerTailnet reachability failures causing agent-specific 502s, without
restarting coderd or enabling debug logging.

- Enrich request logs and PTY/chatd warnings with agent ID, failure
  reason, wait duration, coordinator state, WireGuard handshake and
  byte counts, and DERP regions.
- Add metrics for unreachable attempts by reason, reachability latency,
  embedded DERP connections, and offline app/terminal requests.
- Distinguish reachability failures from subsequent TCP dial failures,
  cap reverse proxy dials at one minute, and exclude expected chatd
  readiness polls and superseded-agent dials from unreachable counts.
- Report missing handshakes as zero time instead of 1970, also fixing
  `coder ping`.

Part of PLAT-680, a sub-issue of PLAT-360.
2026-10-14 14:55:29 -07:00
Ethan 939d05b906 fix(coderd): never dial the embedded DERP region over the network (#30221)
Fixes CLI-9

The `goleak` check in `cli` has been flaking on an idle HTTP connection.
It turns out that's coming from `coder server` shutting down, not the
OIDC links command.

`API.Close` cancels the API context well before it closes the server
tailnet, and since #14680 the embedded DERP region dialer returns `nil`
once that context is done. Unfortunately, `nil` tells `derphttp` to dial
the region over the network instead. So the server dials its own access
URL (`example.com` in tests), gets a 404, falls back to WebSocket, and
our tailscale fork leaves that failed WebSocket connection open forever.

This has only been flaking since #29462, which has the server tailnet
fetch the DERP map straight away rather than after the first 5 second
tick. Before that, most server tests had finished before the tailnet
ever connected to DERP, so there was nothing to reconnect on shutdown.

To fix, the embedded region now gets an already closed conn once
shutdown starts, so the DERP handshake fails and magicsock just backs
off until the tailnet closes. I reproduced the leak by pointing a server
tailnet's embedded region at `example.com` and cancelling the context;
it fails `goleak` without this change and passes with it.
2026-10-05 13:28:26 +11:00
Michael Suchacz 7a27db2635 fix(coderd): fetch the DERP map immediately in the server tailnet (#29462) 2026-09-17 18:12:24 +02:00
Spike Curtis 8c00ebc6ee chore: refactor ServerTailnet to use tailnet.Controllers (#15408)
chore of #14729

Refactors the `ServerTailnet` to use `tailnet.Controller` so that we reuse logic around reconnection and handling control messages, instead of reimplementing.  This unifies our "client" use of the tailscale API across CLI, coderd, and wsproxy.
2024-11-08 13:18:56 +04:00
Spike Curtis 04991f425a fix: set node callback each time we reinit the coordinator in servertailnet (#12140)
I think this will resolve #12136 but lets get a proper test at the system level before closing.

Before this change, we only register the node callback at start of day for the server tailnet.  If the coordinator changes, like we know happens when we are licensed for the PGCoordinator, we close the connection to the old coord, and open a new one to the new coord.

The callback is designed to direct the updates to the new coordinator, but there is nothing that specifically triggers it to fire after we connect to the new coordinator.

If we have STUN, then period re-STUNs will generally get it to fire eventually, but without STUN it we could go indefinitely without a callback.

This PR changes the servertailnet to re-register the callback each time we reconnect to the coordinator.  Registering a callback (even if it's the same callback) triggers an immediate call with our node information, so the new coordinator will have it.
2024-02-14 20:45:31 +04:00
Spike Curtis eb12fd7d92 feat: make ServerTailnet set peers lost when it reconnects to the coordinator (#11682)
Adds support to `ServerTailnet` to set all peers lost before attempting to reconnect to the coordinator. In practice, this only really affects `wsproxy` since coderd has a local connection to the coordinator that only goes down if we're shutting down or change licenses.
2024-01-23 13:17:56 +04:00