fuyou001 commented on PR #10659:
URL: https://github.com/apache/rocketmq/pull/10659#issuecomment-5111510330

   **[P1] Avoid leaving the revive service permanently interrupted**
   
   The current `InterruptedException` handling restores the interrupt flag and 
throws. `PopConsumerService.run()` catches the exception and calls 
`waitForRunning(500)`, but `ServiceThread.waitForRunning()` preserves the 
interrupt status. As a result, every subsequent `Semaphore.acquire()` 
immediately throws again, so a single unexpected interrupt can stop all future 
revive progress and cause a tight error/log loop. The current batch is also 
abandoned before `writeRecords` and `deleteRecords` run.
   
   The normal broker shutdown path calls `PopConsumerService.shutdown()` 
without interrupting the worker; it stops the service through the `stopped` 
flag and `wakeup()`. Therefore, an incidental interrupt while waiting for the 
per-batch semaphore can be consumed and retried:
   
   ```java
   while (true) {
       try {
           semaphore.acquire();
           break;
       } catch (InterruptedException e) {
           // PopConsumerService shutdown uses the stopped flag and wakeup(), 
rather
           // than thread interruption. Do not restore the interrupt flag here;
           // otherwise subsequent acquire() and waitForRunning() calls may 
return
           // immediately and leave the revive service in a permanent busy loop.
           log.warn("Interrupted while acquiring semaphore, retry");
       }
   }
   ```
   
   Please also add a regression test that blocks on the semaphore, interrupts 
the revive thread once, releases the outstanding operation, and verifies that 
the remaining records are processed without repeated exceptions or CPU spinning.
   
   If the inherited `shutdown(true)` path is expected to be supported in the 
future, it should be handled separately by checking the stopped state and 
terminating cleanly instead of swallowing that shutdown interrupt.


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