Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions postgres/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ impl managed::Manager for Manager {
}
}

impl std::panic::UnwindSafe for Manager {}

#[async_trait]
trait Connect: Sync + Send {
async fn connect(&self, pg_config: &PgConfig) -> Result<(PgClient, JoinHandle<()>), Error>;
Expand Down
13 changes: 13 additions & 0 deletions src/managed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ use std::{
future::Future,
marker::PhantomData,
ops::{Deref, DerefMut},
panic::{RefUnwindSafe, UnwindSafe},
sync::{
atomic::{AtomicUsize, Ordering},
Arc, Mutex, Weak,
Expand Down Expand Up @@ -615,6 +616,18 @@ impl<M: Manager, W: From<Object<M>>> Pool<M, W> {
}
}

impl<M: Manager, W: From<Object<M>>> UnwindSafe for Pool<M, W>
where
M: UnwindSafe,
{
}

impl<M: Manager, W: From<Object<M>>> RefUnwindSafe for Pool<M, W>
where
M: UnwindSafe,
{
}

struct PoolInner<M: Manager> {
manager: M,
slots: Mutex<Slots<ObjectInner<M>>>,
Expand Down
7 changes: 7 additions & 0 deletions src/unmanaged/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ impl<T> Object<T> {

impl<T> Drop for Object<T> {
fn drop(&mut self) {
// If we're panicking, there is no way to determine whether the object
// we are dropping is the source of the panic. Therefore, always discard
// the object on a panic, and do not return it to the pool.
if std::thread::panicking() {
return;
}

if let Some(obj) = self.obj.take() {
if let Some(pool) = self.pool.upgrade() {
{
Expand Down