chrisdutz commented on code in PR #19177:
URL: https://github.com/apache/iotdb/pull/19177#discussion_r4505953263
##########
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:
Fixed. `execute()` now checks `allowSubmitListen` under the lock before it
waits. `stopService()` takes the lock with `lock()` instead of `tryLock()` and
signals while it holds it. An iteration either sees the stopped state before it
waits or is already waiting when the signal comes, including one that was still
queued when `stopService()` ran.
`AbstractPeriodicalServiceWithAdvanceTest` covers both cases: stopping a
waiting iteration, and your reproducer (the only executor thread held on a
latch, then `startService()`, `stopService()`, `shutdown()` and release). Both
use a 10-minute interval and expect termination within 5 s. On the previous
code the queued case fails at the 5 s timeout. With the fix both pass in about
60 ms.
`advanceExecution()` keeps `tryLock()`, so an advance can still be missed in
the same way. That is unchanged by this PR and only delays the next run, not
the shutdown.
--
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]