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

   **Issue Evaluation**
   
   Category: `type/bug` | Status: **Confirmed**
   
   The race condition has been verified against 
`common/src/main/java/org/apache/rocketmq/common/ServiceThread.java`.
   
   **Root Cause:**
   In `waitForRunning(long interval)`, after `hasNotified.compareAndSet(true, 
false)` returns `false`, there is a window between `waitPoint.reset()` (line 
116) and `waitPoint.await()` (line 119). If `wakeup()` executes in this window:
   
   1. `wakeup()` → `hasNotified.CAS(false, true)` succeeds → 
`waitPoint.countDown()` sets state from 1 to 0
   2. `waitForRunning()` → `waitPoint.reset()` calls `setState(1)`, resetting 
the latch back to 1
   3. `waitForRunning()` → `waitPoint.await(interval, ...)` blocks for the full 
interval
   
   The wakeup signal is lost because `reset()` undoes the `countDown()`.
   
   **Impact:** Any `ServiceThread` subclass (e.g. `FlushRealTimeService`, 
`AllocateMessageQueueScheduledService`, `ReputMessageService`, etc.) may miss 
wakeup signals under concurrent load, causing latency spikes up to `interval` 
milliseconds.
   
   **Severity:** Medium-High — affects core Broker services that depend on 
timely wakeup for message flush and dispatch.
   
   **Suggested fix direction:** Either make `reset()` + `await()` atomic with 
respect to `wakeup()` (e.g., by synchronizing on a shared lock), or check 
`hasNotified` again after `reset()` and before `await()` to catch the race.
   
   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