-
Notifications
You must be signed in to change notification settings - Fork 125
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
Use futures::lock::Mutex for sharing state between requests #570
Comments
Hm ... this is not so easy. What the error says is basically that the compiler needs to prove that, if any of your handler methods panic, the gotham server can "unwind" that panic and continue running, without leaving the server in any sort of invalid state.
pub struct Mutex<T>(futures_util::lock::Mutex<T>);
// ensure that this is indeed safe!!!!!!!!!
impl<T: ?Sized> RefUnwindSafe for Mutex {}
// these allow calling all the mutex functions
impl<T: ?Sized> Deref for Mutex<T> { ... }
impl<T: ?Sized> DerefMut for Mutex<T> { ... } |
Apparently this is not safe https://stackoverflow.com/questions/69546701/why-does-futureslockmutex-not-implement-refunwindsafe I got your point but in my case, I'm working only async handler. Is there any chance to disable I can study a bit a try to implement the feature, if you want. |
Gotham already uses There is no way to disable catching panics and I have no plan on adding support for that. I recommend you use some mutex implementation that supports poisioning while being future aware. Unfortunately I don't know any such implementations, but I assume someone has encountered that problem before. |
But Things go round and round, is there any chance to resolve this problem in somehow? Thanks for the support |
Hm I can't find a crate that implements a mutex that is future aware and supports poisioning ... I guess you could always use |
It's safe to use You don't risk deadlocking (any more than usual) as long as you don't Also note that keeping a Mutex for a long time, especially while waiting for an external event, is a bad idea with any mutexes, whether futures aware or not. |
@allevo Has your question been answered? |
Yes, but unfortunally there's no way to do that well:
So, the initial question is answered but I don't find a good solution ... |
In this situation I'd try to make |
Yes but that way moves the problem inside: if the method locks the mutex and after makes another |
Hi!
I'm working with futures (i.e my handlers are
async
)Ofter I need to protect my Service around Arc<Mutex<_>> where Arc and Mutex came from std. But when you are working with futures, it's better to use futures::lock::Mutex in order to avoid dead lock (see for example https://users.rust-lang.org/t/std-mutex-vs-futures-mutex-vs-futures-lock-mutex-for-async/41710/2)
So,
the error is
How can I fix this error??
Thanks a lot
The text was updated successfully, but these errors were encountered: