ProblemWith MaxActiveConns set to 1, a connection that has just finished re-authenticating is already idle — yet the very next command can still fail with “connection pool exhausted”. Running a reproduction script against the unfixed code, it hit about 51 times in 1,000 runs under -race.
Root CausegetConn first scans the idle connections with popIdle, but a connection mid-re-authentication is marked InUse and gets skipped. By the time the flow reaches the capacity check, that connection is back to Idle — yet the check only counts connections still flagged Unusable / InUse, so it misjudges the pool as full, goes off to dial, and hits the hard limit.
FixAt the capacity limit, before dialing or erroring out, re-check the idle list once: if a connection has become available, retry claiming it. One check only, no new waiting — the PoolTimeout budget and TryGet's non-blocking semantics stay untouched. The regression test was strengthened to 200 rapid credential rotations with concurrent PINGs, and it fails reliably on the unfixed code.