RockteMQ-AI commented on issue #10543: URL: https://github.com/apache/rocketmq/issues/10543#issuecomment-4777072131
**Automated Fix Proposal — Spec Summary** **Issue:** #10543 — `ServiceThread#wakeup()` race with `waitForRunning()` `waitPoint.reset()` **Category:** `type/bug` | **Severity:** Medium ### Root Cause `CountDownLatch2.reset()` uses unconditional `setState(startCount)`, which overwrites any `countDown()` that occurred between the fast-path CAS failure and `reset()`. The wakeup signal is lost, causing up to 1000ms latency spikes. ### Proposed Fix Replace `CountDownLatch2` with `LockSupport.park/unpark` in `ServiceThread` (common module): - **`wakeup()`**: `hasNotified.set(true)` + `LockSupport.unpark(thread)` - **`waitForRunning()`**: loop with `hasNotified.compareAndSet(true, false)` + `LockSupport.parkNanos(this, nanosRemaining)` - No `reset()` needed — `LockSupport` permits are consumed atomically by `park` ### Files Changed - `common/src/main/java/org/apache/rocketmq/common/ServiceThread.java` — main fix - `common/src/test/java/org/apache/rocketmq/common/ServiceThreadTest.java` — update assertions + add race regression test ### Edge Cases Covered - Shutdown (normal + interrupt) - Multiple wakeup calls (idempotent) - `wakeup()` before `start()` (`unpark(null)` is no-op) - Zero/negative interval - `onWaitEnd()` called exactly once per invocation ### Why This Is Safe - `LockSupport.unpark` grants a retained permit — no reset-vs-countDown race - Public API unchanged (`start`, `shutdown`, `wakeup`, `waitForRunning`, etc.) - `CountDownLatch2` remains in codebase for other usages --- Reply `/approve` to proceed with PR generation. Reply `/revise <feedback>` to request changes to the spec. Reply `/reject` to decline this proposal. --- *Automated fix proposal 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]
