Skip to content

Resolve deadlock between harvest thread and JVM shutdown thread#2539

Merged
jtduffy merged 2 commits intomainfrom
shutdown-hook-deadlock
Mar 31, 2026
Merged

Resolve deadlock between harvest thread and JVM shutdown thread#2539
jtduffy merged 2 commits intomainfrom
shutdown-hook-deadlock

Conversation

@jtduffy
Copy link
Copy Markdown
Contributor

@jtduffy jtduffy commented Oct 30, 2025

Resolves #2514

Replaces the synchronized methods and code blocks with a ReentrantLock instance. In the harvestNow() method, the tryLock() method is called with a 200ms timeout, so even if two threads are fighting for the lock, they will never be deadlocked since the tryLock will timeout and continue.

Wrote a few unit tests to (hopefully) reproduce the scenario and verify no deadlocks occur.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Oct 30, 2025

Codecov Report

❌ Patch coverage is 67.50000% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.30%. Comparing base (fe0fa9e) to head (a319b01).
⚠️ Report is 68 commits behind head on main.

Files with missing lines Patch % Lines
...t/src/main/java/com/newrelic/agent/RPMService.java 67.50% 8 Missing and 5 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2539      +/-   ##
============================================
- Coverage     70.32%   70.30%   -0.02%     
- Complexity    10059    10117      +58     
============================================
  Files           847      855       +8     
  Lines         40913    41109     +196     
  Branches       6201     6232      +31     
============================================
+ Hits          28771    28901     +130     
- Misses         9343     9385      +42     
- Partials       2799     2823      +24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kmudduluru kmudduluru moved this from Triage to Needs Review in Java Engineering Board Nov 4, 2025
@jtduffy jtduffy merged commit bfbb4f5 into main Mar 31, 2026
115 checks passed
@jtduffy jtduffy deleted the shutdown-hook-deadlock branch March 31, 2026 13:15
@github-project-automation github-project-automation Bot moved this from Needs Review to Code Complete/Done in Java Engineering Board Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Deadlock between harvest thread and JVM shutdown hook thread

4 participants