Skip to content

Commit

Permalink
bigtable: add timeout to token refresh (backport #28728) (#28808)
Browse files Browse the repository at this point in the history
bigtable: add timeout to token refresh (#28728)

Co-authored-by: Kirill Fomichev <[email protected]>
(cherry picked from commit 5598570)

Co-authored-by: Brandon Roberts <[email protected]>
  • Loading branch information
mergify[bot] and brandon-j-roberts authored Nov 15, 2022
1 parent 527e2d4 commit 8a6028d
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions storage-bigtable/src/access_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use {
},
time::Instant,
},
tokio::time,
};

fn load_credentials(filepath: Option<String>) -> Result<Credentials, String> {
Expand Down Expand Up @@ -109,15 +110,22 @@ impl AccessToken {
}

info!("Refreshing token");
let new_token = Self::get_token(&self.credentials, &self.scope).await;
match time::timeout(
time::Duration::from_secs(5),
Self::get_token(&self.credentials, &self.scope),
)
.await
{
let mut token_w = self.token.write().unwrap();
match new_token {
Ok(new_token) => *token_w = new_token,
Err(err) => warn!("{}", err),
Ok(new_token) => match (new_token, self.token.write()) {
(Ok(new_token), Ok(mut token_w)) => *token_w = new_token,
(Ok(_new_token), Err(err)) => warn!("{}", err),
(Err(err), _) => warn!("{}", err),
},
Err(_) => {
warn!("Token refresh timeout")
}
self.refresh_active.store(false, Ordering::Relaxed);
}
self.refresh_active.store(false, Ordering::Relaxed);
}

/// Return an access token suitable for use in an HTTP authorization header
Expand Down

0 comments on commit 8a6028d

Please sign in to comment.