Skip to content

Commit

Permalink
Merge pull request redlib-org#158 from redlib-org/oauth_proper_atomics
Browse files Browse the repository at this point in the history
fix(oauth): reset rate limit earlier in refresh cycle
  • Loading branch information
sigaloid authored Jun 27, 2024
2 parents d045a57 + 2e476de commit 023cc85
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 1 deletion.
1 change: 1 addition & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ pub async fn json(path: String, quarantine: bool) -> Result<Value, String> {
let current_rate_limit = OAUTH_RATELIMIT_REMAINING.load(Ordering::Relaxed);
if current_rate_limit < 10 {
warn!("Rate limit {current_rate_limit} is low. Spawning force_refresh_token()");
OAUTH_RATELIMIT_REMAINING.store(99, Ordering::Relaxed);
tokio::spawn(force_refresh_token());
}

Expand Down
1 change: 0 additions & 1 deletion src/oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ pub async fn token_daemon() {
pub async fn force_refresh_token() {
trace!("Rolling over refresh token. Current rate limit: {}", OAUTH_RATELIMIT_REMAINING.load(Ordering::Relaxed));
OAUTH_CLIENT.write().await.refresh().await;
OAUTH_RATELIMIT_REMAINING.store(99, Ordering::Relaxed);
}

#[derive(Debug, Clone, Default)]
Expand Down

0 comments on commit 023cc85

Please sign in to comment.