codelipenghui commented on code in PR #4925:
URL: https://github.com/apache/bookkeeper/pull/4925#discussion_r4460157555
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AuditorElector.java:
##########
@@ -264,6 +273,26 @@ public void shutdown() throws InterruptedException {
log.warn().exception(e).log("Failed to close bookkeeper
client");
}
}
+ if (interrupted != null) {
+ throw interrupted;
+ }
+ }
+
+ /**
+ * Close the auditor manager from another thread than the election one: on
a bookie that is not
+ * the auditor, the election task waits in tryToBecomeAuditor() until the
bookie becomes the
+ * auditor, and closing the manager is what ends that wait. Closing
deletes the vote, which waits
+ * for ZooKeeper to be reachable, so it gets 10 seconds before being
interrupted.
+ */
+ private void closeAuditorManager() throws InterruptedException {
+ Thread closer = new Thread(shutdownTask, "AuditorElector-close-" +
bookieId);
+ closer.setDaemon(true);
+ closer.start();
+ closer.join(TimeUnit.SECONDS.toMillis(10));
+ if (closer.isAlive()) {
+ log.warn("Failed to close auditor manager in 10 seconds,
interrupting");
+ closer.interrupt();
Review Comment:
**P2 — Cancel the closer when its join is interrupted**
If the shutdown caller is interrupted while `join()` waits, it throws before
reaching `closer.interrupt()`. The outer catch only calls
`executor.shutdownNow()`, which cannot interrupt this separate thread. During a
ZooKeeper outage, the closer can therefore keep retrying vote deletion beyond
the intended ten-second bound, retaining the elector and client. Later
`shutdown()` calls return immediately because the election executor is already
shut down.
Please ensure a still-live closer is interrupted on exceptional exit as
well, using a `finally` block or explicit interruption handling, while
retaining the outer cleanup and interruption propagation. A deterministic
regression test should block manager close, interrupt the caller after close
has entered, and verify that the closer receives cancellation; the current
healthy-ZooKeeper interruption test does not cover this path.
--
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]