googleapis / googleapis/google-cloud-rust
Tight infinite busy-loop in token cache refresh on short expiration tokens
- Dominant language
- Rust
- Stars
- 955
- Forks
- 144
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 279
Description
Unconfirmed. This is the result of a search with Gemini, may be a false positive.
In `TokenCache::refresh_task`, the loop calculates sleep duration until expiry using `expiry.checked_duration_since(Instant::now())`:
https://github.com/googleapis/google-cloud-rust/blob/f02b42c2ac5720334cd2b5335824bd4166264527/src/auth/src/token_cache.rs#L180-L196
Specifically lines 186–194:
https://github.com/googleapis/google-cloud-rust/blob/f02b42c2ac5720334cd2b5335824bd4166264527/src/auth/src/token_cache.rs#L186-L194
```rust
if time_until_expiry > NORMAL_REFRESH_SLACK {
sleep(time_until_expiry - NORMAL_REFRESH_SLACK).await;
} else if time_until_expiry > SHORT_REFRESH_SLACK {
// If expiry is less than 4 mins, try to refresh every 10 seconds
// This is to handle cases where MDS **repeatedly** returns about to expire tokens.
sleep(SHORT_REFRESH_SLACK).await;
}
```
If the token provider returns a token expiring in `<= SHORT_REFRESH_SLACK` (10 seconds), or an already-expired token (where `checked_duration_since` returns `None`), neither `if` branch executes.
Because there is no fallback `else` branch or backoff sleep, the loop immediately ends its iteration and restarts, querying `token_provider.token().await` without any delay. If the metadata server (MDS) or auth backend repeatedly returns an about-to-expire token, this leads to an infinite 100% CPU busy loop that hammers the auth server and starves other async tasks.
Contributor guide
Research direction
Start in src/auth/src/token_cache.rs at TokenCache::refresh_task and inspect the expiry handling around lines 180–196. Exercise the loop with tokens expiring within 10 seconds or already expired, then verify that it no longer spins without a delay, repeatedly queries the token provider, or starves other async tasks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- authentication
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 72/100