Repository navigation
Reuse the local client across tailscale_auth requests - #146
Open
caiorondon wants to merge 1 commit into
Open
caiorondon wants to merge 1 commit into
caiorondon wants to merge 1 commit into
Conversation
Signed-off-by: Caio Rondon <caiorondon@gmail.com>
caiorondon
force-pushed
the
fix/reuse-local-client
branch
from
September 25, 2026 01:03
afd0ec3 to
7bad04a
Compare
This was referenced Oct 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Auth.Authenticatehad a value receiver. Its call toclientinitializedlocalclienton a copy ofAuth, so every authentication request created a newlocal.Client. Each client lazily creates its own HTTP transport to the local Tailscale API. The idle Unix connections then accumulate in both Caddy andtailscaled.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_authenabled, 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 newTestAuthenticateReusesLocalClientfails against the parent commit withAuthenticate did not retain its local clientand passes with this change.Tests
go test -race -count=1 ./...