pub struct DeadlockDetector;Expand description
Deadlock detector for workflow analysis.
Provides static analysis of workflow structure to detect:
- Dependency cycles (hard error - prevents execution)
- Resource deadlock patterns (warning - execution continues)
- Long dependency chains (warning - execution continues)
Implementations§
Source§impl DeadlockDetector
impl DeadlockDetector
Sourcepub fn detect_dependency_cycles(
&self,
workflow: &Workflow,
) -> Result<(), DeadlockError>
pub fn detect_dependency_cycles( &self, workflow: &Workflow, ) -> Result<(), DeadlockError>
Detects dependency cycles in the workflow DAG.
Uses Tarjan’s strongly connected components algorithm to find cycles. A cycle indicates tasks that directly or indirectly depend on each other, making execution impossible.
§Arguments
workflow- The workflow to analyze
§Returns
Ok(())if no cycles detectedErr(DeadlockError::DependencyCycle)with cycle path if cycle found
§Example
ⓘ
let detector = DeadlockDetector::new();
if let Err(e) = detector.detect_dependency_cycles(&workflow) {
println!("Cycle detected: {:?}", e);
}Sourcepub fn detect_resource_deadlocks(
&self,
workflow: &Workflow,
) -> Result<Vec<DeadlockWarning>, DeadlockError>
pub fn detect_resource_deadlocks( &self, workflow: &Workflow, ) -> Result<Vec<DeadlockWarning>, DeadlockError>
Analyzes workflow for potential resource deadlocks.
This is a heuristic analysis that generates warnings for:
- Tasks that might share resources (no direct access in our model)
- Long chains of dependent tasks (timeout risk)
- Tasks with no timeout (hang risk)
Note: This function does NOT prevent execution - warnings are informational.
§Arguments
workflow- The workflow to analyze
§Returns
Vector of deadlock warnings (may be empty)
§Example
ⓘ
let detector = DeadlockDetector::new();
let warnings = detector.detect_resource_deadlocks(&workflow)?;
for warning in warnings {
println!("Warning: {}", warning.description());
}Sourcepub fn validate_workflow(
&self,
workflow: &Workflow,
) -> Result<Vec<DeadlockWarning>, DeadlockError>
pub fn validate_workflow( &self, workflow: &Workflow, ) -> Result<Vec<DeadlockWarning>, DeadlockError>
Validates that a workflow is deadlock-free.
This is a convenience method that combines cycle detection and resource deadlock analysis.
§Arguments
workflow- The workflow to validate
§Returns
Ok(Vec<DeadlockWarning>)- Warnings (may be empty) if no hard errorsErr(DeadlockError::DependencyCycle)- If cycle detected
§Example
ⓘ
let detector = DeadlockDetector::new();
match detector.validate_workflow(&workflow) {
Ok(warnings) => {
for warning in warnings {
println!("Warning: {}", warning.description());
}
// Execute workflow
}
Err(e) => {
eprintln!("Cannot execute: {}", e);
}
}Trait Implementations§
Auto Trait Implementations§
impl Freeze for DeadlockDetector
impl RefUnwindSafe for DeadlockDetector
impl Send for DeadlockDetector
impl Sync for DeadlockDetector
impl Unpin for DeadlockDetector
impl UnsafeUnpin for DeadlockDetector
impl UnwindSafe for DeadlockDetector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more