Skip to content

Commit 09bee7f

Browse files
committed
Preserve lease refusal through finalization errors
1 parent cf06cd1 commit 09bee7f

2 files changed

Lines changed: 48 additions & 3 deletions

File tree

‎crates/signal-ops/src/error.rs‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,22 @@ impl OpsError {
4949
pub fn is_fence_lost(&self) -> bool {
5050
match self {
5151
OpsError::Store(e) => state_is_refused(e),
52-
OpsError::Signal(SignalProtocolError::BackendError(_, source)) => source
53-
.downcast_ref::<StoreError>()
54-
.is_some_and(state_is_refused),
52+
OpsError::Signal(error) => signal_state_is_refused(error),
5553
_ => false,
5654
}
5755
}
5856
}
57+
58+
fn signal_state_is_refused(error: &SignalProtocolError) -> bool {
59+
let mut source: Option<&(dyn std::error::Error + 'static)> = Some(error);
60+
while let Some(current) = source {
61+
if current
62+
.downcast_ref::<StoreError>()
63+
.is_some_and(state_is_refused)
64+
{
65+
return true;
66+
}
67+
source = current.source();
68+
}
69+
false
70+
}

‎crates/signal-ops/src/stores.rs‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,4 +528,37 @@ mod tests {
528528
);
529529
});
530530
}
531+
532+
#[test]
533+
fn service_classification_keeps_the_actual_finalization_fence_cause() {
534+
let lost = wacore_recordstore::FenceLost {
535+
scope: "authored-finalization-source".into(),
536+
generation: 7,
537+
}
538+
.into_store_error();
539+
let source = SignalProtocolError::BackendError("authored store", Box::new(lost));
540+
let error = crate::OpsError::Signal(SignalProtocolError::BackendError(
541+
"session finalization",
542+
Box::new(SharedFinalizationError(Arc::new(source))),
543+
));
544+
assert!(
545+
error.is_fence_lost(),
546+
"service lost the fence refusal inside its finalization wrapper"
547+
);
548+
}
549+
550+
#[test]
551+
fn service_classification_does_not_turn_finalization_io_into_fence_loss() {
552+
let source = SignalProtocolError::BackendError(
553+
"authored store",
554+
Box::new(wacore::store::error::StoreError::Io(std::io::Error::other(
555+
"authored ordinary I/O",
556+
))),
557+
);
558+
let error = crate::OpsError::Signal(SignalProtocolError::BackendError(
559+
"session finalization",
560+
Box::new(SharedFinalizationError(Arc::new(source))),
561+
));
562+
assert!(!error.is_fence_lost());
563+
}
531564
}

0 commit comments

Comments
 (0)