codelipenghui commented on code in PR #4926:
URL: https://github.com/apache/bookkeeper/pull/4926#discussion_r4463414160


##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AuditorCheckAllLedgersTask.java:
##########
@@ -245,8 +245,18 @@ void checkAllLedgers() throws BKException, IOException, 
InterruptedException {
                 log.error().exception(ue).log("Got exception while trying to 
set checkAllLedgersCTime");
             }
         } finally {
-            localAdmin.close();
-            localClient.close();
+            // Auditor.shutdown() interrupts a running check: close the 
check's own client with the
+            // interrupt status cleared, or BookKeeper.close() gives up at its 
first wait and leaves
+            // the client's threads and ZooKeeper session behind
+            boolean interrupted = Thread.interrupted();
+            try {
+                localAdmin.close();
+                localClient.close();

Review Comment:
   **[P2] Handle shutdown arriving during the private-client close**
   
   Clearing the flag once handles an interrupt already delivered, but does not 
protect the following close operation. A reachable sequence is:
   
   1. The scan finishes normally and passes `Thread.interrupted()` with no 
interrupt set.
   2. `localClient.close()` sets `closed = true` and starts waiting for its 
scheduler to terminate.
   3. `Auditor.shutdown()` now calls 
[`executor.shutdownNow()`](<https://github.com/apache/bookkeeper/blob/03994c43f2298ca88b63b71b30d3a33d48ef0985/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/Auditor.java#L620-L630>),
 interrupting the same worker while it is closing the client.
   4. The interruptible wait in 
[`BookKeeper.close()`](<https://github.com/apache/bookkeeper/blob/03994c43f2298ca88b63b71b30d3a33d48ef0985/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeper.java#L1527-L1594>)
 throws, skipping the remaining pools, timer, event loops and metadata driver.
   
   This requires only the first shutdown interrupt, not a repeated shutdown or 
a 30-second timeout. The outer auditor does not retain this per-check client, 
and retrying its close would return immediately because it is already marked 
closed.
   
   The [new 
test](<https://github.com/apache/bookkeeper/blob/03994c43f2298ca88b63b71b30d3a33d48ef0985/bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/AuditorPeriodicCheckTest.java#L986-L1001>)
 keeps the scan pending, so its interrupt always arrives before cleanup. Please 
ensure interruption during close cannot abandon resource release—for example, 
finish releasing owned resources before propagating interruption, or perform 
cleanup outside the worker targeted by cancellation—and add a test that 
initiates shutdown after client cleanup has started.



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