Skip to content
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

Value inside Mutex stops being Send when updating to 0.12 from 0.11 #317

Open
vicky5124 opened this issue Feb 5, 2022 · 3 comments
Open

Comments

@vicky5124
Copy link

I've been going through the locks of my library lavalink-rs, making them live as short as possible, not holding them across awaits, etc... It was all fine and good on 0.11, it compiles fine, and the library doesn't deadlock, even in extreme situations, but updating to 0.12, it no longer compiles. The compiler complains about a value not being Send, which makes no sense.

This is the code that fails to compile, with the error in the following image:

14 30 54_05-02-2022

Is the error due to actual poor design? Is this a regression in the library? Or, is this the compiler messing up?

I'm trying to think of ways to solve this by having an alternative design, but the only thing I can think of is refactoring the writer into being a channel instead of a lock, which would be much more work.

@Amanieu
Copy link
Owner

Amanieu commented Feb 5, 2022

You need to enable the send_guard feature if you want to be able to send a MutexGuard to another thread. The reason this is a separate feature is that it is incompatible with the deadlock detector feature.

@vicky5124
Copy link
Author

Enabling the feature does fix compilation. Shouldn't the behaviour be documented? I don't see it being mentioned on Mutex nor MutexGuard

@Amanieu
Copy link
Owner

Amanieu commented Feb 5, 2022

The send_guard option is documented in the README. By default, MutexGuard acts like the one in std which is not Send either.

By the way you really shouldn't be holding a MutexGuard across an await since this can cause a deadlock if tokio switches to another task while your suspended task is holding a lock.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants