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

   **Issue Evaluation**
   
   Category: `type/bug` | Status: **Confirmed**
   
   The reported data race and TOCTOU inconsistency in 
`DefaultLitePullConsumerImpl.taskTable` has been verified against the current 
`develop` branch codebase.
   
   **Root Cause:**
   
   The `startPullTask()` method (line 455-462) uses a non-atomic `containsKey → 
put` pattern on `ConcurrentHashMap`:
   
   ```java
   if (!this.taskTable.containsKey(messageQueue)) {
       PullTaskImpl pullTask = new PullTaskImpl(messageQueue);
       this.taskTable.put(messageQueue, pullTask);
       this.scheduledThreadPoolExecutor.schedule(pullTask, 0, 
TimeUnit.MILLISECONDS);
   }
   ```
   
   This is a classic check-then-act race. Multiple callers 
(`updateAssignPullTask`, `updatePullTask`, rebalance callbacks) can invoke 
`startPullTask` concurrently, leading to:
   
   1. **Duplicate pull tasks** — Two threads both observe `containsKey == 
false` and each schedules a `PullTaskImpl`. The second `put` overwrites the 
first in the map, but the first task keeps running untracked.
   2. **Orphaned queues** — Concurrent iteration+removal in 
`updateAssignPullTask`/`updatePullTask` can remove an entry another thread just 
added, silently stopping polling for that queue.
   
   **Impact:** Silent message consumption stalls or duplicate processing in 
`LitePullConsumer` under concurrent rebalance/assignment scenarios.
   
   **Severity:** Medium-High — silent data path corruption, no exception or log 
to indicate the cause.
   
   **Suggested Fix:**
   - Replace `containsKey + put` with `putIfAbsent` to make the 
check-and-insert atomic.
   - Consider synchronizing the iterate-then-mutate sequences in 
`updateAssignPullTask` / `updatePullTask` / `removePullTask`, or use a 
consistent locking strategy.
   
   An automated fix proposal can 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