JackieTien97 commented on code in PR #19177:
URL: https://github.com/apache/iotdb/pull/19177#discussion_r4505449311


##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/AbstractPeriodicalServiceWithAdvance.java:
##########
@@ -89,6 +89,9 @@ public void startService() {
 
   public void stopService() {
     allowSubmitListen = false;
+    // wake the loop from its interval wait, so that it ends now and its 
executor can
+    // terminate, instead of only after the next interval
+    advanceExecution();

Review Comment:
   **Handle stop before the submitted iteration begins.**
   
   This notification can be lost if `startService()` has submitted `execute()` 
but the worker has not entered it yet. `advanceExecution()` acquires the free 
lock and signals a condition with no waiters; the queued iteration then runs 
`executeTask()` and enters `condition.await(...)`, because the wait checks only 
`skipNextSleep`, not the stopped state. The executor can therefore remain alive 
for the full interval after shutdown (30 seconds by default for 
`GeneralRegionAttributeSecurityService`).
   
   I reproduced this deterministically by holding the executor's sole thread on 
a latch, calling `startService()`, `stopService()`, and `executor.shutdown()`, 
then releasing the latch. The queued iteration still enters the interval wait. 
This also reproduces on the base revision, so it is an uncovered case in the 
shutdown optimization rather than a newly introduced regression.
   
   Please coordinate the stopped-state check and the condition notification 
under the same lock, and add a regression test for stopping while the iteration 
is still queued.



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