iloveeyjafjalla opened a new pull request, #11478:
URL: https://github.com/apache/rocketmq/pull/11478

   ## Which Issue(s) This PR Fixes
   
   Fixes #11477
   
   ## Problem
   
   `BrokerContainer.initialize()` schedules the name-server refresh and the 
five-second `brokerOuterAPI.refreshMetadata()` task on 
`scheduledExecutorService`, and `shutdown()` stops the brokers, both remoting 
servers, the request executor and the outer API - but not that scheduler. A 
shut-down container keeps refreshing metadata through the API it has just 
closed, logging `ScheduledTask refresh metadata exception` every five seconds, 
and leaks the scheduler thread on every start/shutdown cycle. Same shape as 
#11427 and #11456.
   
   ## Change
   
   ```java
           ThreadUtils.shutdown(this.brokerContainerExecutor);
   
   +       // Stop the periodic tasks (name-server refresh and the five-second 
metadata refresh) before
   +       // the API they call is closed, so nothing of the container keeps 
running after shutdown.
   +       ThreadUtils.shutdown(this.scheduledExecutorService);
   
            if (this.brokerOuterAPI != null) {
                this.brokerOuterAPI.shutdown();
            }
   ```
   
   ## Verification
   
   `BrokerContainerTest` gains `testShutdownStopsTheScheduledExecutorTest`, 
which initializes a container, reads the scheduler through reflection and 
asserts it is shut down after `shutdown()`. Before the change:
   
   ```
   testShutdownStopsTheScheduledExecutorTest:96 Expecting value to be true but 
was false
   Tests run: 4, Failures: 1, Errors: 0, Skipped: 1
   ```
   
   After the change, with JDK 8 (`mvn -B -ntp -pl container -am test 
-Dtest='BrokerContainerTest' -DfailIfNoTests=false -Djacoco.skip=true`):
   
   ```
   Tests run: 10, Failures: 0, Errors: 0, Skipped: 0   (the whole 
BrokerContainerTest, 120s)
   BUILD SUCCESS
   spotbugs:4.8.6.8:check: BugInstance size is 0
   checkstyle:3.2.0:check (validate): passed
   ```
   
   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]

Reply via email to