-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unwind safety #139
Comments
As far as I understand the marker trait the core of deadpool should mostly be I have to double check the impl<M: Manager, W: From<Object<M>>> UnwindSafe for Pool<M, W>
where
M: UnwindSafe,
W: UnwindSafe,
{
} The |
I'm seeing a type error with the
The same error is given for |
I keep coming back to this issue and think about it. I do wonder if an object should ever be returned to the pool if it comes from a thread that just panicked. If the object caused the panic it's very likely that it's going to happen again and therefore the object should be considered "broken beyond repair". Though since there is no way to know what caused the panic the worst should be assumed, no? An easy fix would be to check Thinking about it. Maybe this should added as a new configuration variable: /// This flag controls if objects that were dropped as part of a thread
/// panicking should be returned to the pool or not.
///
/// **Note:** There is no way to decide wether the object caused the panic
/// or some user code. So it's usually a safe bet to discard the object just to
/// be sure.
return_on_panic: bool; The default for this should be Besides that maybe a let panic_guard = Object::panic_guard();
/// panic guard enabled. Panics from this point on will
/// not return the object to the pool.
drop(panic_guard);
/// panic guard disabled. Panics from this point on will
/// return the object as usual.
I guess I'm overthinking this. Usually code should not be built around panics and it's probably the best idea to always discard objects on panic. Just to be safe. |
A simple check of |
As a side-note, this is currently blocking deadpool being used in a Gotham Middleware because of the
In the implementation in #139 (comment), I'm not sure I understand why the impl<M: Manager, W: From<Object<M>>> UnwindSafe for Pool<M, W>
where
M: UnwindSafe,
{
} |
Don't return objects to the pool on panic, since we can't be sure whether they were the source of the panic. See-also: bikeshedder#139
Would it be feasible or even make sense to implement
UnwindSafe
for themanaged::Pool
type?Some context: I've decided to replace r2d2 with deadpool-diesel for database connection pooling in an application because r2d2 has a serious flaw in the way it handles panics (see diesel-rs/diesel#2124, diesel-rs/diesel#2105, diesel-rs/diesel#2020, sfackler/r2d2#70).
The
managed::Pool
type not beingUnwindSafe
prevents certain use cases such as passing the pool to an async function that may panic but where the panic needs to be caught. As far as I can tell, because pooled objects are wrapped in a Mutex and deadpool discards poisoned mutexes, there's no risk of reusing an invalid pooled object. (At least this is the case with thediesel
andsqlite
implementations.)The text was updated successfully, but these errors were encountered: