Skip to content

Conversation

@zrlw
Copy link
Contributor

@zrlw zrlw commented Mar 19, 2025

What is the purpose of the change?

see Resolving the Thread-Safety Problem in registerReferenceKeyAndBeanName Using an Overloaded computeIfAbsent #15219

org.apache.dubbo.config.spring.reference.ReferenceBeanManager.java

    public void registerReferenceKeyAndBeanName(String referenceKey, String referenceBeanNameOrAlias) {
        List<String> list =
                ConcurrentHashMapUtils.computeIfAbsent(referenceKeyMap, referenceKey, (key) -> new ArrayList<>());
        if (!list.contains(referenceBeanNameOrAlias)) {
            list.add(referenceBeanNameOrAlias);
            // register bean name as alias
            referenceAliasMap.put(referenceBeanNameOrAlias, list.get(0));
        }
    }

The ConcurrentHashMapUtils.computeIfAbsent method ensures the creation of a new list in a thread-safe manner when no list exists for the given referenceKey. However, the subsequent operations if (!list.contains(referenceBeanNameOrAlias)) and list.add(referenceBeanNameOrAlias) are not atomic. This situation can lead to thread-safety issues where multiple threads might simultaneously pass the contains check and then all perform the add operation, resulting in duplicate referenceBeanNameOrAlias entries within the list.

@AlbumenJ PTAL

Checklist

  • Make sure there is a GitHub_issue field for the change.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction. If the new feature or significant change is committed, please remember to add sample in dubbo samples project.
  • Make sure gitHub actions can pass. Why the workflow is failing and how to fix it?

@codecov-commenter
Copy link

codecov-commenter commented Mar 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.77%. Comparing base (7e351ba) to head (d178544).
⚠️ Report is 174 commits behind head on 3.3.

Additional details and impacted files
@@            Coverage Diff            @@
##                3.3   #15258   +/-   ##
=========================================
  Coverage     60.76%   60.77%           
- Complexity    10892    10898    +6     
=========================================
  Files          1885     1885           
  Lines         86087    86086    -1     
  Branches      12896    12896           
=========================================
+ Hits          52312    52320    +8     
+ Misses        28324    28317    -7     
+ Partials       5451     5449    -2     
Flag Coverage Δ
integration-tests 33.22% <100.00%> (+0.14%) ⬆️
samples-tests 29.25% <100.00%> (+0.04%) ⬆️
unit-tests 58.89% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@AlbumenJ AlbumenJ merged commit d5e1412 into apache:3.3 May 7, 2025
19 checks passed
@zrlw zrlw deleted the 3.3-Optimized-ReferenceBeanManager branch June 5, 2025 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants