-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Fix issue #1898 - Permit::release() must be called when Mutex::lock() is aborted even if it is in the Waiting state #1902
Fix issue #1898 - Permit::release() must be called when Mutex::lock() is aborted even if it is in the Waiting state #1902
Conversation
519fd4c
to
c13853c
Compare
The original code did the following:
Since a Permit must always be released unless it is in the
|
48de2b3
to
472c87b
Compare
Permit::release() must also be called when it is in the waiting state.
472c87b
to
257a904
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, but it would be good to hear from @carllerche as well. I commented on some minor nits.
iv.tick().await; | ||
iv.tick().await; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of the interval here is a little un-obvious, it could be good if there was a comment explaining what it's doing here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that the comment Try to lock mutex in a future that is aborted prematurely
was telling enough. tbh. That test case is not really needed. I just added it when debugging the code and trying to reproduce the locking behaviour. This test just makes sure Aquired
locks are returned when their future is aborted.
Is there a better way to let a future delay its execution than creating an interval and waiting twice? tick().await
is called twice as the first call of it returns instantly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a better way to let a future delay its execution than creating an interval and waiting twice?
tick().await
is called twice as the first call of it returns instantly.
You could possibly just use
task::yield_now().await;
if all you want is to yield to the scheduler so that another task will be polled? But, what you're doing now does make sense, I just thought it would be helpful if there was a comment explaining what it was for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to move forward merging & shipping. We can tweak the test in a follow up PR.
#[tokio::main] | ||
#[test] | ||
/// Ensure a mutex is unlocked if a future holding the lock | ||
/// is aborted prematurely. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: It would be good to reference the GitHub issue that these tests reproduce.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for debugging & fixing 👍
It is possible to leave a mutex in a locked state even if no future exists holding the lock.
I think this should be considered a critical issue as it can be exploited as shown in issue #1898 when using hyper and aborting requests.