Repository navigation
Conversation
When a cached token expires, every GCM process that needs it (for example one per Git worktree, or one per parallel fetch) falls back to interactive authentication on its own. They share one MSAL token cache, so only one sign-in is needed, but after it completes the other processes never look at the cache again and keep prompting or waiting. Take a per-client, per-authority lock file in the GCM data directory before starting an interactive or broker flow. Once the lock is held, resolve the account again and retry silent authentication, so a token stored by another process is used without a second prompt. Waiting honours cancellation and gives up after five minutes. If the lock cannot be taken, authentication continues as before. Verified with four parallel `get` requests against an expired account: before, four device-code flows started; now one starts and three wait. Assisted-by: Claude Sonnet 5.5 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
As demonstrated in initial post of #1555, this is an issue for all providers during parallel requests. Some auth paths would need to keep a lock until the completion ot the |
|
Thanks for looking, and agreed that the underlying problem is not specific to Entra. This PR is intentionally the narrow variant: it only covers flows that go through On the You are right about the case without a binding, though. Because the binding is only recorded in Closing that gap needs something that spans |
Problem
When a cached token expires, every GCM process that needs it (one per Git worktree, one per parallel fetch, an IDE autofetch, ...) falls back to interactive authentication on its own. They share one MSAL token cache, so one sign-in is enough, but after it completes the other processes never look at the cache again. They keep prompting or waiting. In one environment a single token expiry left 189 stray
git fetch/git-credential-manager getprocesses behind.Discussed in #1555 (see my two comments there) and related to #2288.
Change
In
EntraAuthentication.GetTokenForUserAsync, after silent authentication fails and interaction is allowed:entra-signin-<hash>.lockin the GCM data directory (hash of client ID, authority and cache type).Waiting honours cancellation and gives up after 5 minutes. If the lock cannot be taken, authentication continues exactly as before. A file handle is used rather than a named mutex (thread affinity across
await); the OS releases it if the process exits.Verification
EntraAuthenticationInteractiveLockTests).dotnet testrun on Windows: everything passes except 6Trace2MessageTests.BuildTimeSpancases that fail on a Dutch locale (decimal comma) onmainas well; they pass withDOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1.getprocesses for an account missing from the cache (GCM_MSAUTH_FLOW=devicecode):mainstarts 4 device-code flows, this branch starts 1 and the other 3 wait.Not verified
Opened as a draft: the maintainers have said serialization is planned for 3.0, so this is meant as a concrete proposal to react to.
🤖 Generated with Claude Code