Skip to content

Commit 2369564

Browse files
committed
Clear mutex poision if previous host function panicked
Signed-off-by: Ludvig Liljenberg <[email protected]>
1 parent cc0fa1e commit 2369564

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/hyperlight_host/src/func/host_functions.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,21 @@ macro_rules! impl_host_function {
179179
let func = Mutex::new(func);
180180
HostFunction {
181181
func: Arc::new(move |args: ($($P,)*)| {
182-
func.try_lock()
183-
.map_err(|e| new_error!("Error locking at {}:{}: {}", file!(), line!(), e))?
184-
(args)
182+
match func.try_lock() {
183+
Ok(mut guard) => guard(args),
184+
Err(poison_err) => {
185+
match poison_err {
186+
// The previous call to this host function panicked, poisoning the lock.
187+
// We can clear the poison safely.
188+
std::sync::TryLockError::Poisoned(guard) => {
189+
guard.into_inner()(args)
190+
}
191+
std::sync::TryLockError::WouldBlock => {
192+
Err(new_error!("Error locking at {}:{}: mutex would block", file!(), line!()))
193+
}
194+
}
195+
}
196+
}
185197
})
186198
}
187199
}

0 commit comments

Comments
 (0)