wang-jiahua commented on PR #10659:
URL: https://github.com/apache/rocketmq/pull/10659#issuecomment-5200044000
> **[P1] Avoid leaving the revive service permanently interrupted**
@fuyou001 You are right, and this hazard was introduced by my own change:
the previous code did not restore the interrupt flag, so the exception from
`acquire()` incidentally cleared it and the service recovered on the next
round. Restoring the flag turned one incidental interrupt into a permanent busy
loop, given that shutdown here works through the stopped flag and `wakeup()`,
and `ServiceThread.waitForRunning` preserves the interrupt status.
Fixed in `771afdcd4` following your suggestion: incidental interrupts are
consumed and the acquire is retried. If the service is being stopped, which
covers a future `shutdown(true)`, the batch aborts cleanly instead of
swallowing that shutdown interrupt; the records have not been deleted from the
store yet, so they are reprocessed after the next start.
```java
while (true) {
try {
semaphore.acquire();
break;
} catch (InterruptedException e) {
if (this.isStopped()) {
throw new RuntimeException("PopConsumerService stopped while
acquiring the revive semaphore", e);
}
log.warn("PopConsumerService interrupted while acquiring the revive
semaphore, retry");
}
}
```
Added the regression test you described,
`reviveShouldSurviveIncidentalInterruptWhileAcquiringSemaphore`: the
concurrency is set to a single permit and the first read is held open, so the
worker blocks inside `semaphore.acquire()` for the second record; the worker is
then interrupted once and the outstanding read released. The batch completes
normally, returning 2 with the scan window drained, and no exception escapes.
Before this commit the worker dies with `RuntimeException:
java.lang.InterruptedException`.
--
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]