GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add a simple deadlock detector for require locks. by headius · Pull Request #4095 · jruby/jruby

Conversation

@headius

@headius headius commented Aug 20, 2016

Copy link
Copy Markdown
Member

This detector works only with two threads, using the following
heuristic:

  1. If the lock is already acquired, obtain its owner thread.
  2. Check if the owner thread is waiting on a lock.
  3. If the lock the owner is waiting on is held by the current
    thread, raise an error.
  4. If there's no owner and no deadlock, try to lock the thread for
    500ms + rand(100)ms.
  5. If the file has been locked, return success.
  6. Otherwise, start over at 1.

We may want a more advanced detector that can handle arbitrarily
many threads, but it would be much heavier and require scanning
all threads in the system, including those unrelated to the
current program and those not actually trying to require files.

See #3341.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@headius headius added this to the JRuby 9.1.3.0 milestone Aug 20, 2016
@headius headius added core JRuby 9000 discuss concurrency labels Aug 20, 2016
@headius

headius commented Aug 20, 2016

Copy link
Copy Markdown
Member Author

I'm opening this PR to discuss the implementation and seek input.

A few known issues:

  • Hard dependency on management extensions. These are not available on all platforms and I have no fallbacks (nor graceful handling when those extensions are unavailable).
  • Potentially heavy to acquire this info. Does it matter if we only do it for contended threads?
  • Only works for two threads with mutually-exclusive locking. There are algorithms for detecting deadlocks between many threads, but I believe they're NP. I have not researched yet.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@headius

headius commented Aug 20, 2016 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

I made a modification to mitigate known issue 2 above: it now will attempt to lock FIRST, only doing deadlock detection if that attempt fails.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kares

kares commented Aug 20, 2016

Copy link
Copy Markdown
Member

should safe fail when mx (java.lang.management) not available e.g. on Android

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@headius

headius commented Aug 22, 2016

Copy link
Copy Markdown
Member Author

@kares Indeed...it would likely just skip this code.

This general pattern may be applicable elsewhere, so this should move into its own utility class.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@headius
headius force-pushed the require_deadlock branch from 0c53b64 to 2d6762e Compare August 22, 2016 17:30
@headius headius modified the milestones: JRuby 9.1.4.0, JRuby 9.1.3.0 Aug 22, 2016
@headius

headius commented Aug 22, 2016

Copy link
Copy Markdown
Member Author

Punting to 9.1.4.0. Too risky to stitch in at the last moment for 9.1.3.0.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@enebo enebo modified the milestones: JRuby 9.1.4.0, JRuby 9.1.5.0, JRuby 9.1.6.0 Sep 1, 2016
@headius
headius force-pushed the require_deadlock branch from 2d6762e to 58cc903 Compare September 30, 2016 03:57
@headius headius modified the milestones: JRuby 9.1.7.0, JRuby 9.1.6.0 Nov 8, 2016
@headius

headius commented Nov 8, 2016

Copy link
Copy Markdown
Member Author

Needs rebase and more thought. Bumping and rebasing.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

headius added 2 commits November 8, 2016 11:55
@headius
Add a simple deadlock detector for require locks.
38854e1
This detector works only with two threads, using the following
heuristic:

1. If the lock is already acquired, obtain its owner thread.
2. Check if the owner thread is waiting on a lock.
3. If the lock the owner is waiting on is held by the current
   thread, raise an error.
4. If there's no owner and no deadlock, try to lock the thread for
   500ms + rand(100)ms.
5. If the file has been locked, return success.
6. Otherwise, start over at 1.

We may want a more advanced detector that can handle arbitrarily
many threads, but it would be much heavier and require scanning
all threads in the system, including those unrelated to the
current program and those not actually trying to require files.

See #3341.
@headius
Only perform deadlock detection after the first failed lock.
a6e70e3
@headius
headius force-pushed the require_deadlock branch from 58cc903 to a6e70e3 Compare November 8, 2016 17:55
@headius
Missed file from RubyGems 2.6.8 update.
e3db2de
@headius headius added this to the JRuby 9.2.0.0 milestone Dec 14, 2016
@headius headius removed this from the JRuby 9.1.7.0 milestone Dec 14, 2016
@enebo enebo modified the milestones: JRuby 9.2.0.0, JRuby 9.2.1.0 May 24, 2018
@headius headius modified the milestones: JRuby 9.2.1.0, Invalid or Duplicate Oct 11, 2018
@headius

headius commented Oct 11, 2018

Copy link
Copy Markdown
Member Author

De-targeting. This may be useful some day but there's work required and many open questions.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

concurrency core discuss JRuby 9000

Projects

None yet

Milestone

Invalid or Duplicate

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@headius @kares @enebo
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.