You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "ai-yang (via GitHub)" <gi...@apache.org> on 2026/08/15 13:50:38 UTC
[I] [Bug] Shutting down one producer stops timeout flushing for producers with the same client ID` [rocketmq]
ai-yang opened a new issue, #10935:
URL: https://github.com/apache/rocketmq/issues/10935
### Before Creating the Bug Report
- [x] I found a bug, not just asking a question, which should be created in [GitHub Discussions](https://github.com/apache/rocketmq/discussions).
- [x] I have searched the [GitHub Issues](https://github.com/apache/rocketmq/issues) and [GitHub Discussions](https://github.com/apache/rocketmq/discussions) of this repository and believe that this is not a duplicate.
- [x] I have confirmed that this bug belongs to the current repository, not other repositories of RocketMQ.
### Runtime platform environment
Reproduced on Ubuntu 22.04.4 LTS, Linux 5.15.0-186, x86_64. The defect is in the Java client lifecycle and is not expected to be OS-specific.
### RocketMQ version
- Branch: `develop`
- Version: `5.5.0` / current develop sources
- Commit: `293f5885719fc4aa3619446a1900f58ccfcfdd29`
### JDK Version
- OpenJDK 8u492
### Describe the Bug
Proposed severity: **Major availability impact**.
Multiple `DefaultMQProducer` instances with the same RocketMQ client ID share one `ProduceAccumulator` through `MQClientManager`. The client ID is based on client IP, `instanceName`, and unit name, and does not include the producer group.
However, each producer currently starts and shuts down that shared accumulator independently. The service threads ignore repeated starts, while the first producer shutdown stops both the synchronous and asynchronous batch guard threads even when another producer using the accumulator is still running.
After that shutdown:
- under low traffic, a small synchronous auto-batched message can wait indefinitely because it does not reach the size threshold and the timeout guard no longer wakes it;
- a small asynchronous auto-batched message can remain queued without a callback until another send reaches the size threshold.
The surviving producer remains in `RUNNING` state, so the failure is silent and gives the application no useful error to recover from. This is an availability bug, not a security report.
### Steps to Reproduce
reachable NameServer and Broker, create two auto-batching producers in different producer groups but give them the same explicit instance name. Ensure `TopicTest` already exists or topic auto-creation is enabled:
```java
DefaultMQProducer producerA = new DefaultMQProducer("group-a");
DefaultMQProducer producerB = new DefaultMQProducer("group-b");
producerA.setNamesrvAddr(namesrvAddr);
producerB.setNamesrvAddr(namesrvAddr);
producerA.setInstanceName("shared-client");
producerB.setInstanceName("shared-client");
producerA.setAutoBatch(true);
producerB.setAutoBatch(true);
producerA.batchMaxDelayMs(1000);
producerB.batchMaxDelayMs(1000);
producerA.start();
producerB.start();
producerA.shutdown();
// A small message is below the auto-batch size threshold. This call can
// block indefinitely because the shared timeout guard was stopped by A.
producerB.send(new Message("TopicTest", new byte[] {1}));
```
The same defect has a deterministic broker-free unit reproduction:
1. Create one `ProduceAccumulator` with a short `batchMaxDelayMs`.
2. Call `start()` twice to represent two producers sharing the same client ID.
3. Call `shutdown()` once to release only the first producer.
4. Add one small asynchronous message through `MockMQProducer`.
5. Wait longer than `batchMaxDelayMs` for either callback.
On the unmodified baseline, the callback deadline expires every time. Two independent runs of the final public-lifecycle regression failed with method times of 4.817 and 4.829 seconds:
```text
Expecting value to be true but was false
Tests run: 1, Failures: 1
```
### What Did You Expect to See?
Shutting down one producer should release only that producer's ownership of the shared accumulator. As long as another producer with the same client ID is still started, the accumulator guard threads should remain active and flush its messages after `batchMaxDelayMs`.
### What Did You See Instead?
The first producer shutdown stops the shared guard threads immediately. Under low traffic, a remaining producer can then block indefinitely in a synchronous send, or retain an asynchronous message without invoking its callback. A later same-key send that reaches the size threshold can still trigger a size-based flush; the broken behavior is timeout flushing.
### Additional Context
A minimal fix is to reference-count started producer owners in `ProduceAccumulator`: start its guards only on transition `0 -> 1` and stop them only on `1 -> 0`. Each `DefaultMQProducer` should retain and release at most once so repeated `shutdown()` calls cannot decrement another producer's ownership.
With that fix, the new focused suite passes 5/5 tests, and the broader `ProduceAccumulatorTest` plus `DefaultMQProducerTest` run passes 46/46 tests.
Temporary workarounds are to use a unique `instanceName` for each producer or to avoid shutting down any producer that shares the client ID until all such producers are ready to stop.
I searched for reports involving `ProduceAccumulator`, its sync/async guard threads, shared accumulator lifecycle, same `instanceName`, and producer shutdown, and found no duplicate. Related issue [#8806](https://github.com/apache/rocketmq/issues/8806) and its merged fix [#8807](https://github.com/apache/rocketmq/pull/8807) address accidental sharing caused by early initialization. They intentionally retain sharing for producers with the same instance/unit identity and do not manage ownership of the shared accumulator's lifecycle; this report concerns that distinct lifecycle problem.
--
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: commits-unsubscribe@rocketmq.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug] Shutting down one producer stops timeout flushing for producers with the same client ID [rocketmq]
Posted by "RockteMQ-AI (via GitHub)" <gi...@apache.org>.
RockteMQ-AI commented on issue #10935:
URL: https://github.com/apache/rocketmq/issues/10935#issuecomment-5370289516
Hi @ai-yang, thanks for reporting this!
I've analyzed this issue against the codebase and can confirm this appears to be a **real bug**.
**Root Cause:** ProduceAccumulator is shared per clientId by MQClientManager, but ProduceAccumulator.start()/shutdown() and DefaultMQProducer's calls to them are not reference-counted. The first producer shutdown stops the shared guard threads even when another producer using the same accumulator is still running, so timeout-based flushing ceases.
**Affected Files:** client/src/main/java/org/apache/rocketmq/client/producer/ProduceAccumulator.java, client/src/main/java/org/apache/rocketmq/client/producer/DefaultMQProducer.java, client/src/main/java/org/apache/rocketmq/client/impl/MQClientManager.java
**Analysis:** MQClientManager.getOrCreateProduceAccumulator() (client/src/main/java/org/apache/rocketmq/client/impl/MQClientManager.java:68) returns the same ProduceAccumulator for producers with the same clientId (IP + instanceName + unitName, no producer group). DefaultMQProducer.initProduceAccumulator() (DefaultMQProducer.java:1475) obtains that shared instance. On start, DefaultMQProducer.start() (DefaultMQProducer.java:377-379) calls produceAccumulator.start(), and on shutdown DefaultMQProducer.shutdown() (DefaultMQProducer.java:414-416) calls produceAccumulator.shutdown(). ProduceAccumulator.start() (ProduceAccumulator.java:158-161) starts two ServiceThreads, and ProduceAccumulator.shutdown() (ProduceAccumulator.java:163-166) stops them. ServiceThread.start() ignores repeated starts, while ServiceThread.shutdown() unconditionally stops the thread and marks it not started. Therefore, after two producers share the accumulator and the first one shuts down, the guard threads are
stopped even though the second producer is still RUNNING, causing small auto-batched messages to wait indefinitely for the timeout flush.
I'll prepare a fix spec and work on a PR. The community is welcome to provide feedback on the approach before implementation.
---
🤖 *Automated issue analysis by github-manager*
--
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: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug] Shutting down one producer stops timeout flushing for producers with the same client ID [rocketmq]
Posted by "RockteMQ-AI (via GitHub)" <gi...@apache.org>.
RockteMQ-AI commented on issue #10935:
URL: https://github.com/apache/rocketmq/issues/10935#issuecomment-5394939258
**Issue Evaluation**
Category: `bug` | Status: **Confirmed**
Well-documented issue with clear reproduction. When multiple producers share a client ID, shutting down one producer cancels the shared `HashedWheelTimer` accumulator flush task, silently breaking async sends for the remaining producers.
**Root Cause:** `DefaultMQProducerImpl.shutdown()` cancels the shared accumulator timer without checking whether other active producers still depend on it.
**Impact:** Silent data delay — async sends from surviving producers accumulate but never flush until the next producer creates a new timer. In production this manifests as intermittent message delivery delays.
**Severity:** Medium-High
The proposed fix (reference-counted shared timer, or per-producer accumulator isolation) is appropriate. The reference-counting approach is cleaner for backward compatibility.
---
*Automated evaluation by github-manager*
--
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: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug] Shutting down one producer stops timeout flushing for producers with the same client ID [rocketmq]
Posted by "RockteMQ-AI (via GitHub)" <gi...@apache.org>.
RockteMQ-AI commented on issue #10935:
URL: https://github.com/apache/rocketmq/issues/10935#issuecomment-5302575840
**Issue Evaluation**
Category: `bug` | Status: **Under Review**
Thank you for reporting this issue. Based on the information provided, this appears to be a valid bug report with relevant error details.
**Initial Assessment:**
- Error/exception details: ✅ Present
- Version information: ✅ Present
- Reproduction context: ✅ Present
This issue has been flagged for deeper code-level verification. A fix proposal may be generated after verification.
---
*Automated evaluation by RockteMQ-AI*
--
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: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug] Shutting down one producer stops timeout flushing for producers with the same client ID [rocketmq]
Posted by "RockteMQ-AI (via GitHub)" <gi...@apache.org>.
RockteMQ-AI commented on issue #10935:
URL: https://github.com/apache/rocketmq/issues/10935#issuecomment-5472906665
The feedback window for this proposal has expired (72 hours with no response). The proposed fix spec is no longer being actively tracked.
If you would still like to proceed with this fix, please comment and the proposal will be re-evaluated.
---
*Automated by RockteMQ-AI*
--
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: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug] Shutting down one producer stops timeout flushing for producers with the same client ID [rocketmq]
Posted by "ai-yang (via GitHub)" <gi...@apache.org>.
ai-yang commented on issue #10935:
URL: https://github.com/apache/rocketmq/issues/10935#issuecomment-5634028685
I would like to proceed with this fix. An implementation is already available in #10937; please re-evaluate the existing PR.
The PR reference-counts the shared `ProduceAccumulator` lifecycle and makes acquisition/release idempotent per producer. The regression covers repeated start/shutdown and keeping the shared accumulator active for a surviving producer.
As checked on 2026-09-11, all 10 CI checks pass on head `ce2e9b171e2aa2e0b64084ff7ca65f6064e6de6d`. The PR records 46/46 affected tests passing. Current `develop` has not modified the affected production files since that verification.
@RongtongJin @drpmma, could you take a human review of #10937 when convenient, especially the shared lifecycle and last-owner shutdown behavior? Please use the existing PR for coordination; no additional implementation PR is needed.
--
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: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org