Skip to content

Commit 2216358

Browse files
committed
Fix possible panic in SyncWrapper::interact
1 parent 46ce093 commit 2216358

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

sync/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
## [Unreleased]
1111

12+
- Fix `panic` when dropping a `SyncWrapper` while it is still executing the `interact` method.
13+
1214
## [0.1.3] - 2024-05-24
1315

1416
- Add `LICENSE-APACHE` and `LICENSE-MIT` files to published crates

sync/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ pub enum InteractError {
3737
/// Provided callback has panicked.
3838
Panic(Box<dyn Any + Send + 'static>),
3939

40-
/// Callback was aborted.
40+
/// Callback was aborted. This variant needs to exist for technical
41+
/// reasons but you should never actually be able to get this as a
42+
/// return value when calling `SyncWrapper::interact`.
4143
Aborted,
4244
}
4345

@@ -119,13 +121,13 @@ where
119121
self.runtime
120122
.spawn_blocking(move || {
121123
let mut guard = arc.lock().unwrap();
122-
let conn = guard.as_mut().unwrap();
124+
let conn: &mut T = guard.as_mut().ok_or(InteractError::Aborted)?;
123125
#[cfg(feature = "tracing")]
124126
let _span = span.enter();
125-
f(conn)
127+
Ok(f(conn))
126128
})
127129
.await
128-
.map_err(|SpawnBlockingError::Panic(p)| InteractError::Panic(p))
130+
.map_err(|SpawnBlockingError::Panic(p)| InteractError::Panic(p))?
129131
}
130132

131133
/// Indicates whether the underlying [`Mutex`] has been poisoned.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy