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

Make sure locks are added immediately after acquisition #6407

Merged
merged 3 commits into from Sep 22, 2020

Conversation

headius
Copy link
Member

@headius headius commented Sep 21, 2020

There's a race doing the lock add after the executeTask, since a thread event could interrupt the flow and bypass that logic. A finally would not be appropriate, since an interrupted attempt to acquire the lock would then stil add it. Instead we just move the lock add immediately after lockInterruptibly. If we reach this point, the lock is locked by the current thread, and must be added.

I am looking over the rest of the lock management code in Thread to see if there's other places that could be a risk, but this appears to fix the issue reported in #6405 and probably fixes the issue in #6326.

@headius headius added this to the JRuby 9.2.14.0 milestone Sep 21, 2020
There's a race doing the lock add after the executeTask, since a
thread event could interrupt the flow and bypass that logic. A
finally would not be appropriate, since an interrupted attempt to
acquire the lock would then stil add it. Instead we just move the
lock add immediately after lockInterruptibly. If we reach this
point, the lock is locked by the current thread, and must be
added.

Fixes jruby#6405 and maybe jruby#6326.
It should never happen that there's a lock in the current-thread's
list of locked locks that is not actually locked, but if so we
should not allow this error to prevent unlocking the others. We
warn that this is a bug and proceed to the remaining locks.
@headius
Copy link
Member Author

headius commented Sep 21, 2020

Tracked down the regression to bea9ad4 (released in 9.2.8.0).

@headius
Copy link
Member Author

headius commented Sep 22, 2020

I made the unlocking at thread disposition more robust, but did not see any other risky pieces of code related to locking. We'll go with this.

@headius headius merged commit f2da4eb into jruby:jruby-9.2 Sep 22, 2020
@headius headius deleted the harden_lock_mgmt branch September 22, 2020 00:53
@headius headius linked an issue Sep 30, 2020 that may be closed by this pull request
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

Successfully merging this pull request may close these issues.

Thread kill does not release lock
1 participant