wy471x opened a new pull request, #6945:
URL: https://github.com/apache/shenyu/pull/6945

   <!-- Describe your PR here; e.g. Fixes #issueNo -->
   
   <!--
   Thank you for proposing a pull request. This template will guide you through 
the essential steps necessary for a pull request.
   -->
   Make sure that:
   
   - [X] You have read the [contribution 
guidelines](https://shenyu.apache.org/community/contributor-guide).
   - [X] You submit test cases (unit or integration tests) that back your 
changes.
   - [X] Your local test passed `./mvnw clean install 
-Dmaven.javadoc.skip=true`.
   
   ## Summary
   
   ### Changes:
     
   Fix: lost-update race in SubscribeRepository.add()
     Both add() overloads used a get-then-put pattern: get(topic) returned a 
transient CopyOnWriteArrayList for an absent topic (via getOrDefault), the 
channel was added to that transient list, then the list was put into 
TOPIC_CHANNEL_FACTORY. Under concurrent subscription to a new topic, each 
thread obtained its own empty list and the last put won —silently dropping the 
first subscriber.
   
    Fix: both overloads now use TOPIC_CHANNEL_FACTORY.computeIfAbsent(topic, t 
-> new CopyOnWriteArrayList<>()) to atomically obtain the canonical list stored 
in the map, followed by a thread-safe add/addAll on the CopyOnWriteArrayList.
   
   ### Test Cases:
     
   Tests: unit tests for SubscribeRepository
   Added SubscribeRepositoryTest with 4 tests: basic registration via both 
add() overloads, plus two concurrency regression tests asserting 50 concurrent 
subscribers to a new topic are all retained.
   
   close [#6746](https://github.com/apache/shenyu/issues/6746)


-- 
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