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


##########
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:
   Moved the close of the check's client to a thread of its own, which the 
check waits for without giving up when interrupted (then restores the interrupt 
status), so the shutdown's interrupt no longer reaches `BookKeeper.close()`, 
whether it arrives before or during the close. The new 
`testShutdownWhileCheckAllLedgersClosesItsClient` holds the close on a task 
still running on the client's scheduler, shuts the auditor down, and lets the 
task end once the auditor has stopped running: it fails on 03994c43f2 (`The 
check's client still runs its worker threads`, the close interrupted at 
`scheduler.awaitTermination()`) and passes with b1c6f4ab8d.
   
   _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
   



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