Skip to content

Fix deadlock in getCommit - #1460

Merged
bitwiseman merged 1 commit into
hub4j:mainfrom
scottrw93:patch-1
May 27, 2022
Merged

Fix deadlock in getCommit#1460
bitwiseman merged 1 commit into
hub4j:mainfrom
scottrw93:patch-1

Conversation

@scottrw93

Copy link
Copy Markdown
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".

@codecov

codecovBot commented May 22, 2022

Copy link
Copy Markdown

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 FilesCoverage Δ
src/main/java/org/kohsuke/github/GHRepository.java68.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.

@bitwisemanbitwiseman left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
ContributorAuthor

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

@bitwiseman
bitwiseman merged commit 0257ebb into hub4j:mainMay 27, 2022
@scottrw93
scottrw93 deleted the patch-1 branch June 9, 2022 21:40
Sign up for freeto 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.

2 participants

@scottrw93@bitwiseman