Repository navigation
Backport #12446: Fix deadlock in AbstractRequestCache - #12468
Merged
Merged
Conversation
… parent POMs (apache#12446) * Fix apache#12445: Fix deadlock in AbstractRequestCache when resolving parent POMs Replace the wait/notify pattern in AbstractRequestCache.requests() with direct value setting via CachingSupplier.complete(). The old pattern stored a wait-based individualSupplier in CachingSupplier instances cached across calls. When a re-entrant requests() call (e.g., parent POM resolution during artifact resolution) retrieved a CachingSupplier from the cache, it would invoke the outer call's individualSupplier, which waited on a HashMap that would never be notified — deadlock. The fix: - Add CachingSupplier.complete() to set values without invoking the supplier - Pass a single-item fallback supplier to doCache() so newly created CachingSuppliers can independently resolve requests in re-entrant scenarios - After batch resolution, directly set results via complete() - Remove the synchronized wait/notify on HashMap entirely Co-Authored-By: Claude Opus 4.6 <[email protected]> * Fix apache#12445: Prevent duplicate concurrent resolutions via wait/notifyAll coordination Add ThreadLocal re-entrancy detection and CachingSupplier.setBatchResolving() so that concurrent threads wait for an in-progress batch result (via Object.wait/notifyAll) instead of resolving the same request independently, while same-thread re-entrant calls still use the fallback supplier to avoid deadlock. Also fix CachingTestRequestCache to use ConcurrentHashMap, clean up duplicate javadoc, and add concurrent resolution test. Co-Authored-By: Claude Opus 4.6 <[email protected]> * Fix apache#12445: Use IdentityHashMap for reqToIndex to handle unstable hashCode ResolverRequest.hashCode() can change during batch resolution because RequestTrace includes mutable ModelBuilderRequest data (identified in PR apache#12166). Since reqToIndex always uses the same object references for put and get, IdentityHashMap is safe and avoids missed lookups that would cause redundant individual resolutions. Co-Authored-By: Claude Opus 4.6 <[email protected]> * Fix apache#12445: Add test for batch resolution with unstable hashCode Verify that batch results are correctly delivered via complete() even when request hashCode() changes during resolution (simulating ResolverRequest with mutable RequestTrace/ModelBuilderRequest data). The IdentityHashMap-based reqToIndex ensures lookups succeed by reference identity regardless of hashCode mutations. Co-Authored-By: Claude Opus 4.6 <[email protected]> * Fix apache#12445: Address Copilot review — consistent error handling and safe unblocking - catch(Throwable) now falls through to the collection loop and produces a proper BatchRequestException with per-request results, consistent with the MavenExecutionException path. - setBatchResolving(false) now calls notifyAll() to unblock any threads still waiting in apply() when complete() was never called (e.g., batch supplier returned fewer results than expected). - Add test for partial batch result edge case. Co-Authored-By: Claude Opus 4.6 <[email protected]> --------- Co-authored-by: Claude Opus 4.6 <[email protected]>
gnodet
marked this pull request as ready for review
July 11, 2026 16:52
gnodet
commented
Jul 11, 2026
gnodet
left a comment
Contributor
Author
There was a problem hiding this comment.
Review Summary
Clean backport of #12446 (deadlock fix in AbstractRequestCache) to the 4.0.x branch.
Observations:
- Single-commit cherry-pick of the squash-merge commit — clean and reviewable
- Final file states for
AbstractRequestCache.javaandCachingSupplier.javaare bit-identical to master (matching blob SHAs), confirming a faithful port - The 4.0.x baseline had a
CyclicCacheAccessException-based re-entrancy approach which the backport correctly replaces with the newThreadLocal-based re-entrancy detection andbatchResolving/complete()coordination pattern - All 5 new tests (deadlock re-entrancy, concurrent deduplication, unstable hashCode, partial batch unblocking, batch result caching) plus 3 helper classes are included, matching the original PR exactly
LGTM — own PR, cannot approve.
Claude Code on behalf of Guillaume Nodet
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Contributor
|
@gnodet Please assign appropriate label to PR according to the type of change. |
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.
Summary
Backport of #12446, which fixes #12445.
Cherry-pick of squash-merge commit c6de104 from
mastertomaven-4.0.x.The fix replaces the wait/notify pattern in
AbstractRequestCache.requests()with direct value setting viaCachingSupplier.complete(), preventing deadlocks when re-entrantrequests()calls occur (e.g., parent POM resolution during artifact resolution). It also addsThreadLocalre-entrancy detection andsetBatchResolving()so concurrent threads wait for in-progress batch results while same-thread re-entrant calls use a fallback supplier.Conflicts were resolved during cherry-pick (the 4.0.x branch had a
CyclicCacheAccessException-based approach that was replaced by the new batch-resolution pattern).Test plan
AbstractRequestCacheTestpasses (included in this backport)🤖 Generated with Claude Code