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

Prevent endless loop in lock cycle detection. The following scenario would previously fail: #1681

Closed
wants to merge 0 commits into from

Conversation

copybara-service[bot]
Copy link

Prevent endless loop in lock cycle detection. The following scenario would previously fail:

  • T1: Enter lockOrDetectPotentialLocksCycle:
    • Lock CAF.class, add itself to lockThreadIsWaitingOn, unlock CAF.class
    • Lock the cycle detecting lock (CDL)
    • Lock CAF.class, mark itself as lockOwnerThread, remove itself from lockThreadIsWaitingOn
    • Exit lockOrDetectPotentialLocksCycle
  • T1: Re-enter lockOrDetectPotentialLocksCycle:
    • Lock CAF.class, add itself to lockThreadIsWaitingOn, unlock CAF.class
      T2: Enter lockOrDetectPotentialLocksCycle
    • Lock CAF.class, invoke detectPotentialLocksCycle.

At this point, detectPotentialLocksCycle will now loop forever, because the lockOwnerThread is also in lockThreadIsWaitingOn. During the course of looping forever, it will OOM, because it's building up an in-memory structure of what it thinks are cycles.

The solution is to avoid the re-entrant T1 from adding itself to lockThreadIsWaitingOn if it's already the lockOwnerThread. It's guaranteed that it won't relinquish the lock concurrently, because it's the exact same thread that owns it.

Fixes #1635 and Fixes #1510

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.

Cycle detection in a multi-thread environment leads to OutOfMemoryError
0 participants