Skip to content

Reuse the local client across tailscale_auth requests - #146

Open
caiorondon wants to merge 1 commit into
tailscale:mainfrom
caiorondon:fix/reuse-local-client
Open

caiorondon wants to merge 1 commit into
tailscale:mainfrom
caiorondon:fix/reuse-local-client

Conversation

@caiorondon

Copy link
Copy Markdown

Summary

Auth.Authenticate had a value receiver. Its call to client initialized localclient on a copy of Auth, so every authentication request created a new local.Client. Each client lazily creates its own HTTP transport to the local Tailscale API. The idle Unix connections then accumulate in both Caddy and tailscaled.

Use a pointer receiver so the client persists across requests. Guard lazy initialization with a mutex so concurrent requests share one client without a data race; an initialization error can still be retried on a later request.

Reproduction

With tailscale_auth enabled, 15 sequential requests added approximately 15 open Unix socket descriptors in each process. A long-running proxy accumulated more than 11,000 descriptors per process. The new TestAuthenticateReusesLocalClient fails against the parent commit with Authenticate did not retain its local client and passes with this change.

Tests

  • go test -race -count=1 ./...

Signed-off-by: Caio Rondon <caiorondon@gmail.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.

1 participant