Fix deadlock in NamespacedHierarchicalStore.computeIfAbsent()#5348
Merged
mpkorstanje merged 7 commits intoFeb 11, 2026
Conversation
8190262 to
e09a285
Compare
✅ All tests passed ✅🏷️ Commit: 874ec9d Learn more about TestLens at testlens.app. |
e09a285 to
fdc46c3
Compare
marcphilipp
approved these changes
Feb 8, 2026
marcphilipp
left a comment
Member
There was a problem hiding this comment.
Thanks for taking care of this! The reasoning makes sense to me. I only added a few nitpicks regarding explanatory comment.
Co-authored-by: Marc Philipp <mail@marcphilipp.de>
marcphilipp
pushed a commit
that referenced
this pull request
Feb 15, 2026
In #5231 evaluation of the default value creator was deferred until after an entry was created in the concurrent hash map backing the store. This enables recursive updates. However, by calling `evaluateIfNotNull` inside `compute` threads that lost the race would wait inside `Map::compute` for the value to be evaluated. Waiting here is a problem when the backing concurrent hashmap is reaching capacity. The thread waiting inside compute holds a lock while at the same time the thread that won the race will try to acquire a lock to resize the map. By making the threads that lost the race wait outside of `Map::compute` we can prevent this dead lock. This does require that each thread retries when another thread failed to insert a value. But eventually either one other thread either successfully inserts a value or the thread uses its own default value creator. Fixes: #5346 Co-authored-by: Marc Philipp <mail@marcphilipp.de> (cherry picked from commit f29de38)
marcphilipp
pushed a commit
that referenced
this pull request
Feb 15, 2026
In #5231 evaluation of the default value creator was deferred until after an entry was created in the concurrent hash map backing the store. This enables recursive updates. However, by calling `evaluateIfNotNull` inside `compute` threads that lost the race would wait inside `Map::compute` for the value to be evaluated. Waiting here is a problem when the backing concurrent hashmap is reaching capacity. The thread waiting inside compute holds a lock while at the same time the thread that won the race will try to acquire a lock to resize the map. By making the threads that lost the race wait outside of `Map::compute` we can prevent this dead lock. This does require that each thread retries when another thread failed to insert a value. But eventually either one other thread either successfully inserts a value or the thread uses its own default value creator. Fixes: #5346 Co-authored-by: Marc Philipp <mail@marcphilipp.de> (cherry picked from commit f29de38)
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.
In #5231 evaluation of the default value creator was deferred until after an entry was created in the concurrent hash map backing the store. This enables recursive updates. However, by calling
evaluateIfNotNullinsidecomputethreads that lost the race would wait insideMap::computefor the value to be evaluated.junit-framework/junit-platform-engine/src/main/java/org/junit/platform/engine/support/store/NamespacedHierarchicalStore.java
Lines 272 to 280 in bfd70fd
Waiting here is a problem when the backing concurrent hashmap is reaching capacity. The thread waiting inside compute holds a lock while at the same time the thread that won the race will try to acquire a lock to resize the map.
By making the threads that lost the race wait outside of
Map::computewe can prevent this dead lock. This does require that each thread retries when another thread failed to insert a value. But eventually either one other thread either successfully inserts a value or the thread uses its own default value creator.Fixes: #5346
I hereby agree to the terms of the JUnit Contributor License Agreement.
Definition of Done
@APIannotations