bigtable: add timeout to token refresh (#28728)
Co-authored-by: Kirill Fomichev <fanatid@ya.ru>
This commit is contained in:
parent
d4cf18421d
commit
55985701ba
|
@ -16,6 +16,7 @@ use {
|
||||||
},
|
},
|
||||||
time::Instant,
|
time::Instant,
|
||||||
},
|
},
|
||||||
|
tokio::time,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn load_credentials(filepath: Option<String>) -> Result<Credentials, String> {
|
fn load_credentials(filepath: Option<String>) -> Result<Credentials, String> {
|
||||||
|
@ -109,15 +110,22 @@ impl AccessToken {
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Refreshing token");
|
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();
|
Ok(new_token) => match (new_token, self.token.write()) {
|
||||||
match new_token {
|
(Ok(new_token), Ok(mut token_w)) => *token_w = new_token,
|
||||||
Ok(new_token) => *token_w = new_token,
|
(Ok(_new_token), Err(err)) => warn!("{}", err),
|
||||||
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
|
/// Return an access token suitable for use in an HTTP authorization header
|
||||||
|
|
Loading…
Reference in New Issue