-
Notifications
You must be signed in to change notification settings - Fork 255
Bugfix: Add circuit breaker #6143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
aa0d15e
67c32fa
bc0b89b
6dce55a
08559a7
c61df79
fd5a95f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,32 +19,47 @@ pub(crate) struct RuntimeRegistry { | |
| pub enum RegistryAccessError { | ||
| #[error("the runtime registry is poisoned")] | ||
| Poisoned, | ||
|
|
||
| #[error("The SDK ShutdownManager already exists")] | ||
| ExistingShutdownManager, | ||
|
|
||
| #[error("No existing SDK ShutdownManager")] | ||
| MissingShutdownManager, | ||
| } | ||
|
|
||
| impl RuntimeRegistry { | ||
| /// Get or create a ShutdownManager for SDK use. | ||
| /// Create a ShutdownManager for SDK use. | ||
| /// This manager doesn't listen to OS signals, making it suitable for library use. | ||
| pub(crate) fn get_or_create_sdk() -> Result<Arc<ShutdownManager>, RegistryAccessError> { | ||
| let guard = REGISTRY | ||
| .sdk_manager | ||
| .read() | ||
| .map_err(|_| RegistryAccessError::Poisoned)?; | ||
| if let Some(manager) = guard.as_ref() { | ||
| return Ok(manager.clone()); | ||
| } | ||
| drop(guard); | ||
|
|
||
| /// This function overwrite any existing manager! | ||
| pub(crate) fn create_sdk() -> Result<Arc<ShutdownManager>, RegistryAccessError> { | ||
| let mut guard = REGISTRY | ||
| .sdk_manager | ||
| .write() | ||
| .map_err(|_| RegistryAccessError::Poisoned)?; | ||
|
|
||
| Ok(guard | ||
| .get_or_insert_with(|| { | ||
| Arc::new(ShutdownManager::new_without_signals().with_cancel_on_panic()) | ||
| }) | ||
| .insert(Arc::new( | ||
| ShutdownManager::new_without_signals().with_cancel_on_panic(), | ||
| )) | ||
| .clone()) | ||
| } | ||
|
|
||
| /// Get the ShutdownManager for SDK use. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| /// This manager doesn't listen to OS signals, making it suitable for library use. | ||
| /// Not yet used, but maybe in the future | ||
| #[allow(dead_code)] | ||
| pub(crate) fn get_sdk() -> Result<Arc<ShutdownManager>, RegistryAccessError> { | ||
| let guard = REGISTRY | ||
| .sdk_manager | ||
| .read() | ||
| .map_err(|_| RegistryAccessError::Poisoned)?; | ||
| if let Some(manager) = guard.as_ref() { | ||
| Ok(manager.clone()) | ||
| } else { | ||
| Err(RegistryAccessError::MissingShutdownManager) | ||
| } | ||
| } | ||
|
|
||
| /// Check if an SDK manager has been created. | ||
| /// Useful for testing and debugging. | ||
| #[allow(dead_code)] | ||
|
|
@@ -85,10 +100,13 @@ mod tests { | |
|
|
||
| assert!(!RuntimeRegistry::has_sdk_manager().unwrap()); | ||
|
|
||
| let manager1 = RuntimeRegistry::get_or_create_sdk().unwrap(); | ||
| // Error if nothing was created | ||
| assert!(RuntimeRegistry::get_sdk().is_err()); | ||
|
|
||
| let manager1 = RuntimeRegistry::create_sdk().unwrap(); | ||
| assert!(RuntimeRegistry::has_sdk_manager().unwrap()); | ||
|
|
||
| let manager2 = RuntimeRegistry::get_or_create_sdk().unwrap(); | ||
| let manager2 = RuntimeRegistry::get_sdk().unwrap(); | ||
| // Should return the same instance | ||
| assert!(Arc::ptr_eq(&manager1, &manager2)); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -736,15 +736,11 @@ where | |||
| base_builder = base_builder.with_topology_provider(topology_provider); | ||||
| } | ||||
|
|
||||
| // Use custom shutdown if provided, otherwise get from registry | ||||
| let shutdown_tracker = match self.custom_shutdown { | ||||
| Some(custom) => custom, | ||||
| None => { | ||||
| // Auto-create from registry for SDK use | ||||
| nym_task::get_sdk_shutdown_tracker()? | ||||
| } | ||||
| }; | ||||
| base_builder = base_builder.with_shutdown(shutdown_tracker); | ||||
| // Use custom shutdown if provided, otherwise the sdk one will be used later down the line | ||||
| if let Some(shutdown_tracker) = self.custom_shutdown { | ||||
| base_builder = base_builder.with_shutdown(shutdown_tracker); | ||||
| } | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so why do we no longer get the default static one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We still need it, but it was set a first time here, and then later in the base client startup too. There is no point in setting it in two places There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reference :
I'd be fine with setting it up there and remove it here mentioned. Then |
||||
|
|
||||
| if let Some(event_tx) = self.event_tx { | ||||
| base_builder = base_builder.with_event_tx(event_tx); | ||||
| } | ||||
|
|
@@ -809,7 +805,7 @@ where | |||
| client_output, | ||||
| client_state.clone(), | ||||
| nym_address, | ||||
| started_client.shutdown_handle.child_tracker(), | ||||
| started_client.shutdown_handle.clone(), | ||||
| packet_type, | ||||
| ); | ||||
|
|
||||
|
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did you change the existing behaviour to overwrite a pre-existing shutdown manager? this could be potentially dangereous, especially if it had already registered some signals, tasks, etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a global shutdown means that if you cancel the underlying token, you can never spin up a new mixnet client again, because the underlying token will be cancelled to start with.
The SDK manager is only used if no other shutdown manager is provided