Fix deadlock in NamespacedHierarchicalStore.computeIfAbsent() by mpkorstanje · Pull Request #5348 · junit-team/junit-framework (original) (raw)

@mpkorstanje

@mpkorstanje

@mpkorstanje

marcphilipp

@mpkorstanje @marcphilipp

Co-authored-by: Marc Philipp mail@marcphilipp.de

@mpkorstanje

@mpkorstanje

@mpkorstanje

@mpkorstanje mpkorstanje deleted the rien/fix-namespaced-hierarchical-store-deadlock branch

February 11, 2026 21:10

marcphilipp pushed a commit that referenced this pull request

Feb 15, 2026

@mpkorstanje @marcphilipp

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

@mpkorstanje @marcphilipp

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

[ Show hidden characters]({{ revealButtonHref }})