You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If f() panics, it will do so while the lock is held. This poisons the lock. Every attempt to interact() thereafter will panic!() because of the unwrap() on line 144 (itself because of the unwrap() in 142). I would suggest the following changes:
Use a non-poisoning lock, like parking_lot::Mutex().
Propagate errors from spawn_blocking(), don't panic.
Alternatively, detect the error and close the connection so that the poisoned mutex is never reused.
The text was updated successfully, but these errors were encountered:
I wonder what's the best practice. My gut feeling is the following:
The interact method should return a Result<InteractError, R>:
/// This error is returned when the call to [`Connection::interact`]/// fails.#[derive(Debug)]pubenumInteractError{/// The provided callback panickedPanic(Box<dynAny + Send + 'static>),/// The callback was abortedAborted,/// rusqlite returned an errorRusqlite(rusqlite::Error),}
Panics should can be propagated using this struct. The InteractError has a variant called Rusqlite so users can use ? inside the function and no double nesting takes place.
When recycling connections detect the poisoned mutex and throw away that connection. Actually I feel like this is the correct approach anyways as that panic could've happened inside the rusqlite code and there is no safe way to check what caused the panic.
Here's the
interact
method, for reference:deadpool/sqlite/src/lib.rs
Lines 136 to 146 in 2c7a0b7
If
f()
panics, it will do so while the lock is held. This poisons the lock. Every attempt tointeract()
thereafter willpanic!()
because of theunwrap()
on line 144 (itself because of theunwrap()
in 142). I would suggest the following changes:parking_lot::Mutex()
.spawn_blocking()
, don't panic.Alternatively, detect the error and close the connection so that the poisoned mutex is never reused.
The text was updated successfully, but these errors were encountered: