gnodet opened a new pull request, #12446:
URL: https://github.com/apache/maven/pull/12446

   ## Summary
   
   - Fix deadlock in `AbstractRequestCache.requests()` that caused Maven 4 to 
hang indefinitely when building with an empty local repository (e.g., 
`-Dmaven.repo.local=/tmp/fresh-repo`)
   - Replace the `Object.wait()/notify()` pattern with direct value setting via 
`CachingSupplier.complete()`, eliminating the re-entrant deadlock scenario
   - Add tests for the re-entrant scenario and batch caching behavior
   
   ## Root Cause
   
   The `requests()` method used a wait/notify pattern with a local `HashMap` 
(`nonCachedResults`):
   1. An `individualSupplier` lambda was created that called 
`nonCachedResults.wait()`, expecting the batch resolution to populate results 
and call `notifyAll()`
   2. This `individualSupplier` was stored inside `CachingSupplier` instances 
via `doCache()`, which cached them by request key
   3. When a re-entrant `requests()` call occurred (e.g., parent POM resolution 
during artifact resolution), `doCache()` returned a `CachingSupplier` from the 
outer call — wrapping the outer call's `individualSupplier`
   4. The inner call's collection loop invoked this `CachingSupplier`, which 
waited on the outer call's `nonCachedResults` — a `HashMap` that could never be 
populated because the outer batch supplier was blocked waiting for the inner 
call to complete
   
   ## Fix
   
   - Added `CachingSupplier.complete(Object result)` to directly set cached 
values without invoking the supplier
   - Changed `requests()` to pass a single-item fallback supplier to 
`doCache()` (instead of the wait-based `individualSupplier`), so any re-entrant 
retrieval can resolve independently
   - After batch resolution, results are set directly on `CachingSupplier` 
instances via `complete()`
   - Removed the `synchronized` wait/notify pattern on `HashMap` entirely
   
   ## Test plan
   
   - [x] Added `testReentrantRequestsDoesNotDeadlock` — reproduces the exact 
deadlock scenario (with 5-second timeout detection)
   - [x] Added `testBatchResultsAreCached` — verifies batch results are 
properly cached for subsequent calls
   - [x] All 499 existing tests in `maven-impl` pass
   - [x] Full reactor build (`mvn clean install -DskipTests`) succeeds
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to