ai-yang opened a new pull request, #10937:
URL: https://github.com/apache/rocketmq/pull/10937

   ### Which Issue(s) This PR Fixes
   
   - Fixes #10935
   
   ### Brief Description
   
   `MQClientManager` can return the same `ProduceAccumulator` to multiple 
producers that share a RocketMQ client ID. Previously, every 
`DefaultMQProducer.shutdown()` stopped that shared accumulator, even if another 
producer using it was still running. Under low traffic, its small synchronous 
auto-batched sends could then wait indefinitely, while asynchronous messages 
remained queued without a callback because timeout flushing had stopped.
   
   This change:
   
   - reference-counts started producer owners inside `ProduceAccumulator`;
   - starts the sync and async guard services only for the first owner;
   - stops the guard services only after the last owner shuts down;
   - tracks accumulator ownership in each `DefaultMQProducer` with an 
`AtomicBoolean`, making accumulator release idempotent across repeated shutdown 
calls;
   - adds regression coverage for both shared lifetime and repeated shutdown.
   
   There is no public API or wire-format change.
   
   ### How Did You Test This Change?
   
   The new lifecycle regression was first applied to the unmodified `develop` 
baseline. It wires the same accumulator into two real `DefaultMQProducer` 
instances, starts both through the public lifecycle methods, shuts down one 
producer, queues a small asynchronous message, and waits for its callback. Two 
baseline runs failed deterministically after the callback deadline:
   
   ```text
   Tests run: 1, Failures: 1
   Expecting value to be true but was false
   BUILD FAILURE
   ```
   
   With this change, the complete `ProduceAccumulatorTest` suite passes:
   
   ```text
   Tests run: 5, Failures: 0, Errors: 0, Skipped: 0
   BUILD SUCCESS
   ```
   
   I also ran all existing `DefaultMQProducerTest` cases together with the 
accumulator tests:
   
   ```text
   Tests run: 46, Failures: 0, Errors: 0, Skipped: 0
   BUILD SUCCESS
   ```
   
   Command:
   
   ```bash
   mvn -o -Dmaven.repo.local=/tmp/rocketmq-bug-m2 \
     -pl client -am -DskipITs \
     -Dcheckstyle.skip -Dspotbugs.skip -Drat.skip \
     -Dsurefire.failIfNoSpecifiedTests=false \
     -Dtest=ProduceAccumulatorTest,DefaultMQProducerTest test
   ```
   
   `git diff --check` also passes.
   


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