You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
tailscale_auth leaks LocalAPI connections on every config reload, even with #140 or #146 #147
#140 and #146 stop the per-request connection leak in tailscale_auth, but a second leak remains: every config reload strands connections to tailscaled until Caddy exits. A small change fixes both.
Cause
On the system tailscaled path, each Auth module builds its own local.Client. Caddy provisions new modules on every config load, so a reload replaces them. local.Client has no Close, its default http.Transport has no IdleConnTimeout, and the transport's goroutines keep the idle connections alive after the module is gone.
Reproduction
Run this with Tailscale up and a Caddy build that includes #140 or #146:
It prints 3, 6, 9, 12, 15, 18: one more connection per route per reload. --force is needed because Caddy skips a reload when the config is unchanged.
Measurements
Caddy v2.11.4, caddy-tailscale de41b249af4f, tailscale.com v1.102.2, on macOS with Tailscale 1.104.1. 20 tailscale_auth routes and 380 authenticated requests, 200 of them concurrent. Each cell is that Caddy process's established LocalAPI connections, read from netstat.
Use one process-wide client for the system tailscaled path:
varsystemLocalClient=new(local.Client)
ifta.localclient==nil {
// default to the shared client that will talk to local tailscaledta.localclient=systemLocalClient
}
The last table row is this change alone on de41b249af4f, with no receiver change or mutex. client() returns the same client even when Authenticate runs on a copy of Auth, so it stops the per-request leak as well. The tsnet path already uses its server's client and is unchanged, though I only tested the system tailscaled path.
Activity