Fix ConcurrentHashMap contention in ExtensionHolderFactoryImpl#2816
Merged
jtduffy merged 2 commits intonewrelic:mainfrom Apr 6, 2026
Merged
Conversation
Replace computeIfAbsent() with putIfAbsent pattern to avoid bin-level locking during value creation. This prevents thread contention issues where threads get stuck in ConcurrentHashMap.helpTransfer() under high concurrency scenarios. The fix uses a double-check pattern: 1. Fast path check with get() 2. Create value outside any lock 3. Atomic putIfAbsent - only one thread wins Trade-off: Under race conditions, multiple threads may create extension instances, but only one wins. This is safe because valueLoader creates empty/stateless instances. This issue was observed in production environments with high thread counts causing application hangs due to ConcurrentHashMap internal contention. Ref: NewRelic Support Case #00311074
Tests verify: - Basic get/remove extension functionality - High concurrency access to same instance key - High concurrency access with different instance keys - Contention scenario with slow value loader These tests confirm the putIfAbsent pattern handles concurrent access without causing thread contention issues.
0154129 to
5f7d937
Compare
jtduffy
approved these changes
Apr 6, 2026
Contributor
|
@rdara |
kanderson250
added a commit
that referenced
this pull request
Apr 6, 2026
Revert "Merge pull request #2816 from rdara/fix/concurrent-hashmap-contention-case-00311074"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Before contributing, please read our contributing guidelines and code of conduct.
Overview
Replace computeIfAbsent() with putIfAbsent pattern to avoid bin-level locking during value creation. This prevents thread contention issues where threads get stuck in ConcurrentHashMap.helpTransfer() under high concurrency scenarios.
The fix uses a double-check pattern:
Trade-off: Under race conditions, multiple threads may create extension instances, but only one wins. This is safe because valueLoader creates empty/stateless instances.
This issue was observed in production environments with high thread counts causing application hangs due to ConcurrentHashMap internal contention.
Ref: NewRelic Support Case #00311074
Related Github Issue
N/A - Issue reported via NewRelic Support Case #00311074
Testing
Checks