Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/auth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ tokio = { workspace = true, features = ["macros", "rt-multi-thre
tokio-test.workspace = true
url.workspace = true
mutants.workspace = true
static_assertions = { workspace = true }

[features]
default = ["default-idtoken-backend", "default-rustls-provider"]
Expand Down
18 changes: 18 additions & 0 deletions src/auth/src/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use gax::retry_loop_internal::retry_loop;
use gax::retry_policy::{AlwaysRetry, RetryPolicy, RetryPolicyArg, RetryPolicyExt};
use gax::retry_throttler::{AdaptiveThrottler, RetryThrottlerArg, SharedRetryThrottler};
use std::error::Error;
use std::panic::{RefUnwindSafe, UnwindSafe};
use std::sync::{Arc, Mutex};

#[derive(Debug)]
Expand All @@ -40,6 +41,17 @@ pub(crate) struct Builder {
retry_throttler: Option<RetryThrottlerArg>,
}

// This is necessary because adding [Builder] to existing, released auth features
// caused a breaking change. The containing structs would lose their automatically derived
// `RefUnwindSafe` implementation because the dynamic trait objects (like `dyn RetryPolicy`)
// are not `RefUnwindSafe` nor `UnwindSafe` by default.
//
// This is safe because in the builder, we never call or use the retry policies. We just hold them
// until we create the client. There is no opportunity for a panic to leave them in an inconsistent
// state.
impl RefUnwindSafe for Builder {}
impl UnwindSafe for Builder {}

impl Builder {
pub(crate) fn with_retry_policy(mut self, retry_policy: RetryPolicyArg) -> Self {
self.retry_policy = Some(retry_policy);
Expand Down Expand Up @@ -142,6 +154,7 @@ mod tests {
use gax::retry_state::RetryState;
use gax::retry_throttler::RetryThrottler;
use mockall::{Sequence, mock};
use static_assertions::assert_impl_all;
use std::error::Error;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
Expand Down Expand Up @@ -479,4 +492,9 @@ mod tests {
original_error_string
);
}

#[test]
fn test_unwind_safe() {
assert_impl_all!(Builder: std::panic::UnwindSafe, std::panic::RefUnwindSafe);
}
}
Loading