RockteMQ-AI commented on issue #11309:
URL: https://github.com/apache/rocketmq/issues/11309#issuecomment-6101106991

   **Issue Evaluation**
   
   Category: `type/bug` (concurrency) | Status: **Confirmed**
   
   The reported race condition is valid. Code analysis confirms:
   
   **Root Cause:**
   - `DefaultMQPushConsumerImpl.shutdown()` (line 903) is `synchronized` and 
calls `rebalanceImpl.destroy()` at line 913
   - `DefaultMQPushConsumerImpl.tryRebalance()` (line 1397) is **not 
synchronized** and only checks `this.pause`, without verifying `serviceState`
   - The asynchronous rebalance path (`RebalanceService` → 
`MQClientInstance.doRebalance()` → `tryRebalance()`) can execute concurrently 
with or after `shutdown()`
   
   **Impact:** As described — orphan `ProcessQueue` instances that are no 
longer managed by `processQueueTable` but still referenced by queued 
`PullRequest` objects. This causes resource leakage, missing cleanup, and 
inconsistent state, especially during frequent consumer restarts with shared 
`MQClientInstance`.
   
   **Severity:** Medium — affects consumer lifecycle correctness, more likely 
under high-frequency restart scenarios.
   
   **Suggested Fix Direction:**
   Add a `serviceState` check in `tryRebalance()` before delegating to 
`rebalanceImpl.doRebalance()`:
   ```java
   public boolean tryRebalance() {
       if (this.serviceState != ServiceState.RUNNING) {
           return false;
       }
       if (!this.pause) {
           return this.rebalanceImpl.doRebalance(this.isConsumeOrderly());
       }
       return false;
   }
   ```
   
   An automated fix proposal will be generated. Reply `/approve` to proceed 
with PR generation.
   
   ---
   *Automated evaluation by github-manager-bot*


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