iloveeyjafjalla opened a new pull request, #11457:
URL: https://github.com/apache/rocketmq/pull/11457
## Which Issue(s) This PR Fixes
Fixes #11456
## Problem
`RemotingProtocolServer`'s constructor schedules `cleanExpireRequest` on a
single-thread `ScheduledExecutorService` built with `ThreadFactoryBuilder`
(non-daemon threads):
```java
this.timerExecutor.scheduleAtFixedRate(this::cleanExpireRequest, 100, 100,
TimeUnit.MILLISECONDS);
```
`shutdown()` stops the eight remoting executors and leaves `timerExecutor`
running, so a shut-down server keeps a live thread running the 100 ms cleanup
task against stopped state, and the non-daemon thread keeps the JVM alive after
the context closes. This is the same shape as #11427 (a service created in a
constructor that the owner's shutdown never stops).
## Change
Stop the timer with the other executors:
```java
this.defaultExecutor.shutdown();
+ // The constructor schedules the expired-request cleanup on this
executor; leaving it running
+ // keeps a non-daemon thread (and its 100ms task) alive after the
server has shut down.
+ this.timerExecutor.shutdown();
}
```
## Verification
`RemotingProtocolServerTest` gains
`testShutdownStopsTheExpiredRequestTimer`, which injects mocks for every
collaborator `shutdown()` touches and verifies the timer is stopped. With the
old code:
```
Wanted but not invoked:
scheduledExecutorService.shutdown();
Tests run: 2, Failures: 1, Errors: 0, Skipped: 1
```
After the change, with JDK 8 (`mvn -B -ntp -pl proxy -am test
-Dtest='RemotingProtocolServerTest' -DfailIfNoTests=false -Djacoco.skip=true`):
```
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS
spotbugs:4.8.6.8:check: BugInstance size is 0
checkstyle:3.2.0:check (validate): passed
```
The test pins the whole shutdown contract, so a future executor started in
this class cannot be added without also being stopped. The change was prepared
with AI assistance and reviewed, tested and verified by me.
--
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]