fix(oauth): handle extremely rare race condition by atomically compare_exchanging

This commit is contained in:
Matthew Esposito 2024-06-27 23:32:17 -04:00
parent 4e2ec3fbc9
commit 13083e999c

View File

@ -131,7 +131,11 @@ pub async fn token_daemon() {
} }
pub async fn force_refresh_token() { pub async fn force_refresh_token() {
OAUTH_IS_ROLLING_OVER.store(true, Ordering::SeqCst); if !OAUTH_IS_ROLLING_OVER.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst).is_ok() {
trace!("Skipping refresh token roll over, already in progress");
return;
}
trace!("Rolling over refresh token. Current rate limit: {}", OAUTH_RATELIMIT_REMAINING.load(Ordering::SeqCst)); trace!("Rolling over refresh token. Current rate limit: {}", OAUTH_RATELIMIT_REMAINING.load(Ordering::SeqCst));
OAUTH_CLIENT.write().await.refresh().await; OAUTH_CLIENT.write().await.refresh().await;
OAUTH_RATELIMIT_REMAINING.store(99, Ordering::SeqCst); OAUTH_RATELIMIT_REMAINING.store(99, Ordering::SeqCst);