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

Fix deadlock in getCommit #1460

Merged
merged 1 commit into from
May 27, 2022
Merged

Fix deadlock in getCommit #1460

merged 1 commit into from
May 27, 2022

Conversation

scottrw93
Copy link
Contributor

Description

We are seeing infrequent deadlocks using the GHRepository::getCommit from a threadpool.

thread dump snippet

 #17072 daemon prio=5 os_prio=0 cpu=943046.99ms elapsed=8709.52s tid=0x00007f3ca82a5fb0 nid=0x8de9 runnable [0x00007f3903353000] java.lang.Thread.State: RUNNABLE at java.util.WeakHashMap.get(java.base@11.0.5/WeakHashMap.java:404) at org.kohsuke.github.GHRepository.getCommit(GHRepository.java:1627) at

WeakHashMap is not threadsafe, and using Collections.synchronisedMap is the recommended way of making it so if this client should be usable concurrently?

Before submitting a PR:

  • Changes must not break binary backwards compatibility. If you are unclear on how to make the change you think is needed while maintaining backward compatibility, CONTRIBUTING.md for details.
  • Add JavaDocs and other comments as appropriate. Consider including links in comments to relevant documentation on https://docs.github.com/en/rest .
  • Add tests that cover any added or changed code. This generally requires capturing snapshot test data. See CONTRIBUTING.md for details.
  • Run mvn -D enable-ci clean install site locally. If this command doesn't succeed, your change will not pass CI.
  • Push your changes to a branch other than main. You will create your PR from that branch.

When creating a PR:

  • Fill in the "Description" above with clear summary of the changes. This includes:
    • If this PR fixes one or more issues, include "Fixes #" lines for each issue.
    • Provide links to relevant documentation on https://docs.github.com/en/rest where possible.
  • All lines of new code should be covered by tests as reported by code coverage. Any lines that are not covered must have PR comments explaining why they cannot be covered. For example, "Reaching this particular exception is hard and is not a particular common scenario."
  • Enable "Allow edits from maintainers".

@bitwiseman bitwiseman added the bug label May 21, 2022
@codecov
Copy link

codecov bot commented May 22, 2022

Codecov Report

Merging #1460 (f29f24a) into main (aa363a5) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##               main    #1460   +/-   ##
=========================================
  Coverage     78.76%   78.76%           
  Complexity     2100     2100           
=========================================
  Files           201      201           
  Lines          6390     6390           
  Branches        359      359           
=========================================
  Hits           5033     5033           
  Misses         1149     1149           
  Partials        208      208           
Impacted Files Coverage Δ
src/main/java/org/kohsuke/github/GHRepository.java 68.34% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update aa363a5...f29f24a. Read the comment docs.

Copy link
Member

@bitwiseman bitwiseman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not clear why we're even using WeakHashMap here, but in terms of making theses particular fields not deadlock, this seems like a low risk change.

@scottrw93
Copy link
Contributor Author

I think WeakHashMap is used just to reduce memory footprint in #468. Similar idea explained here

@bitwiseman bitwiseman merged commit 0257ebb into hub4j:main May 27, 2022
@scottrw93 scottrw93 deleted the patch-1 branch June 9, 2022 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants