Skip to content

Commit

Permalink
Drop the read guard explicitly
Browse files Browse the repository at this point in the history
Signed-off-by: kazk <kazk.dev@gmail.com>
  • Loading branch information
kazk committed Feb 20, 2022
1 parent 4f441f4 commit b2fc0ff
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions kube-client/src/client/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,13 @@ impl RefreshableToken {
}

RefreshableToken::File(token_file) => {
if let Some(header) = {
// Drop `RwLockReadGuard` before a write lock attempt to prevent deadlock.
let guard = token_file.read().await;
guard.cached_token().map(bearer_header)
} {
header
} else {
bearer_header(token_file.write().await.token())
let guard = token_file.read().await;
if let Some(header) = guard.cached_token().map(bearer_header) {
return header;
}
// Drop the read guard before a write lock attempt to prevent deadlock.
drop(guard);
bearer_header(token_file.write().await.token())
}

#[cfg(feature = "oauth")]
Expand Down

0 comments on commit b2fc0ff

Please sign in to comment.