TIL: Its not as hard as I thought to make Rust deadlock

This commit is contained in:
Grant Limberg 2021-12-15 14:37:06 -08:00
parent b567e91f68
commit 0ab5cce878
No known key found for this signature in database
GPG key ID: 2BA62CCABBB4095A

View file

@ -343,6 +343,7 @@ impl ZeroIDC {
fn do_token_exchange(&mut self, code: &str) {
let local = Arc::clone(&self.inner);
let mut should_start = false;
(*local.lock().unwrap()).as_opt().map(|i| {
if let Some(verifier) = i.pkce_verifier.take() {
let token_response = i.oidc_client.as_ref().map(|c| {
@ -378,7 +379,7 @@ impl ZeroIDC {
if split.len() == 2 {
let params = [("id_token", id_token.to_string()),("state", split[0].to_string())];
let client = reqwest::blocking::Client::new();
let res = client.post((*self.inner.lock().unwrap()).auth_endpoint.clone())
let res = client.post(i.auth_endpoint.clone())
.form(&params)
.send();
@ -390,20 +391,20 @@ impl ZeroIDC {
let at = tok.access_token().secret();
let exp = dangerous_insecure_decode::<Exp>(&at);
if let Ok(e) = exp {
(*self.inner.lock().unwrap()).exp_time = e.claims.exp
i.exp_time = e.claims.exp
}
(*self.inner.lock().unwrap()).access_token = Some(tok.access_token().clone());
i.access_token = Some(tok.access_token().clone());
if let Some(t) = tok.refresh_token() {
(*self.inner.lock().unwrap()).refresh_token = Some(t.clone());
self.start();
i.refresh_token = Some(t.clone());
should_start = true;
}
},
Err(res) => {
println!("hit url: {}", res.url().unwrap().as_str());
println!("Status: {}", res.status().unwrap());
println!("Post error: {}", res.to_string());
(*self.inner.lock().unwrap()).exp_time = 0;
i.exp_time = 0;
}
}
@ -418,6 +419,9 @@ impl ZeroIDC {
}
}
});
if should_start {
self.start();
}
}
}