Skip to content

auth: share one LocalAPI client across tailscale_auth modules - #148

Open
anuragbanerjee wants to merge 1 commit into
tailscale:mainfrom
anuragbanerjee:fix/shared-localclient
Open

anuragbanerjee wants to merge 1 commit into
tailscale:mainfrom
anuragbanerjee:fix/shared-localclient

Conversation

@anuragbanerjee

Copy link
Copy Markdown

Every tailscale_auth module on the system tailscaled path builds its own local.Client, and a client can't close its idle connections. Authenticate's value receiver strands one on every request, which #140 and #146 fix. Caddy building new modules strands one on every config reload, which neither of them covers.

This uses one process-wide client on that path, which stops both leaks with no receiver change or mutex. The tsnet path already uses its server's client and is unchanged. The same change also works on top of #140 if you'd rather land that first.

Established LocalAPI connections with 20 tailscale_auth routes and 380 authenticated requests, on macOS with Tailscale 1.104.1. The reproduction is in #147.

Build Before reloads After 5 reloads
de41b249af4f 280 380
+ #140 20 120
+ #146 20 120
This PR 1 1

Testing:

  • go test -race ./... passes, golangci-lint v2.12.0 reports no new issues, and the new test fails without the change.
  • 50 of 50 off-tailnet requests got 401 before and after a reload, and a tailnet request resolved the right identity both times.
  • Tested on macOS with the system tailscaled only, not on Linux or with a tsnet listener.

Fixes #147

Each Auth on the system tailscaled path built its own local.Client, and
a client cannot close its idle connections. Authenticate's value
receiver stranded one per request, and Caddy building new modules on
each config load stranded one per reload. One process-wide client stops
both.

Fixes tailscale#147

Change-Id: Ib5ae8d26152e0b2a3a6d213064ed7ce4a39f34de
Signed-off-by: Anurag Banerjee <anuragbanerjee@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tailscale_auth leaks LocalAPI connections on every config reload, even with #140 or #146

1 participant