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

Enforce Mutex.unlock contract #2401

Closed
qwwdfsad opened this issue Nov 18, 2020 · 1 comment
Closed

Enforce Mutex.unlock contract #2401

qwwdfsad opened this issue Nov 18, 2020 · 1 comment

Comments

@qwwdfsad
Copy link
Collaborator

Background

Mutex API allows to pass an optional and arbitrary owner token to its methods, lock and unlock. This token can be used as a piece of additional debugging information to ensure Mutex ownership and catch programmatic errors early.
If a user tries to unlock a mutex with an owner different from the one it was locked with, the mutex will throw IllegalStateException.

Bug

The following call sequence is currently allowed by the implementation:

mutex.lock(someOwner)
mutex.unlock() // No owner at all

This behaviour becomes even trickier when the owner is operated as Any? in the user code, increasing the chances for null to sneak in.

Proposed change

Throw an IllegalStateException when no owner was supplied to unlock call for the mutex locked with the non-null owner.

qwwdfsad added a commit that referenced this issue Jun 29, 2021
    * Ensure that when unlock without an owner cannot successfully unlock Mutex that was originally locked with an owner

Fixes #2401
@qwwdfsad
Copy link
Collaborator Author

We've discussed it and decided that the potential disturbance does not worth it

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

No branches or pull requests

1 participant