Skip to content

Commit f7e6aa3

Browse files
momobelweiznich
authored andcommitted
sync_wrapper: Provide underlying guard under poison
1 parent d978ff1 commit f7e6aa3

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/sync_connection_wrapper.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,11 @@ impl<C> SyncConnectionWrapper<C> {
235235
{
236236
let inner = self.inner.clone();
237237
tokio::task::spawn_blocking(move || {
238-
let mut inner = inner
239-
.lock()
240-
.expect("Mutex is poisoned, a thread must have panicked holding it.");
238+
let mut inner = inner.lock().unwrap_or_else(|poison| {
239+
// try to be resilient by providing the guard
240+
inner.clear_poison();
241+
poison.into_inner()
242+
});
241243
task(&mut inner)
242244
})
243245
.unwrap_or_else(|err| QueryResult::Err(from_tokio_join_error(err)))
@@ -268,9 +270,11 @@ impl<C> SyncConnectionWrapper<C> {
268270

269271
let (collect_bind_result, collector_data) = {
270272
let exclusive = self.inner.clone();
271-
let mut inner = exclusive
272-
.lock()
273-
.expect("Mutex is poisoned, a thread must have panicked holding it.");
273+
let mut inner = exclusive.lock().unwrap_or_else(|poison| {
274+
// try to be resilient by providing the guard
275+
exclusive.clear_poison();
276+
poison.into_inner()
277+
});
274278
let mut bind_collector =
275279
<<C::Backend as Backend>::BindCollector<'_> as Default>::default();
276280
let metadata_lookup = inner.metadata_lookup();

0 commit comments

Comments
 (0)