mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-09-07 00:24:17 +08:00
A single *Auth is shared by every concurrent request that selects the same credential, so any path reaching into Auth.Metadata directly races the others. The credential identity helpers initialized and wrote the map outside claudeDevicePoolMu; only EnsureDeviceIDPool took the lock, so a lazy `auth.Metadata = make(...)` racing a pool write could abort the whole process with "concurrent map writes" instead of failing a request. Locking only the device-pool helpers was not enough: the account-profile and refresh paths kept mutating the same map unguarded, which a concurrency probe surfaced as data races. Widen the lock to the whole metadata map and route the remaining call sites through new accessors in internal/auth/claude, including the lazy map initialization, which needs a pointer to the field to stay inside the critical section. claudeAccountProfileLookupDue now takes the already-read timestamp so it cannot be handed an unsynchronized map.