Skip to content

Commit 67b4df9

Browse files
committed
add CrossProcessLockError::LockPoisoned
1 parent e289c56 commit 67b4df9

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

crates/matrix-sdk-common/src/cross_process_lock.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ where
240240
// function, to avoid multiple reentrant calls.
241241
let mut _attempt = self.locking_attempt.lock().await;
242242

243+
// The lock is already poisoned? Let's stop here.
244+
if self.is_poisoned() {
245+
return Err(CrossProcessLockError::LockPoisoned);
246+
}
247+
243248
// If another thread obtained the lock, make sure to only superficially increase
244249
// the number of holders, and carry on.
245250
if self.num_holders.load(Ordering::SeqCst) > 0 {
@@ -274,6 +279,8 @@ where
274279
"The lock has been acquired, but it's been poisoned!"
275280
);
276281
self.is_poisoned.store(true, Ordering::SeqCst);
282+
283+
return Err(CrossProcessLockError::LockPoisoned);
277284
}
278285

279286
// This was the same generation, no problem.
@@ -340,6 +347,11 @@ where
340347
}
341348
}
342349

350+
// The lock has been poisoned. Exit the loop.
351+
if this.is_poisoned() {
352+
break;
353+
}
354+
343355
sleep(Duration::from_millis(EXTEND_LEASE_EVERY_MS)).await;
344356

345357
match this
@@ -459,6 +471,11 @@ pub enum CrossProcessLockError {
459471
#[error("a lock timed out")]
460472
LockTimeout,
461473

474+
/// The lock has been poisoned, it means an holder took it before the lock
475+
/// was acquired or renewed.
476+
#[error("a lock has been poisoned")]
477+
LockPoisoned,
478+
462479
#[error(transparent)]
463480
#[cfg(not(target_family = "wasm"))]
464481
TryLockError(#[from] Box<dyn Error + Send + Sync>),

0 commit comments

Comments
 (0)