Skip to content

Commit

Permalink
[hotfix] Do not use ExecutorService.submit since it can swallow excep…
Browse files Browse the repository at this point in the history
…tions

This commit changes the KubernetesLeaderElector to use ExecutorService.execute instead of submit
which ensures that potential exceptions are forwarded to the fatal uncaught exeception handler.

This closes apache#15740.
  • Loading branch information
tillrohrmann committed Apr 26, 2021
1 parent 1f31505 commit fb31e28
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public class KubernetesLeaderElector {
@VisibleForTesting
public static final String LEADER_ANNOTATION_KEY = "control-plane.alpha.kubernetes.io/leader";

private final Object lock = new Object();

private final ExecutorService executorService =
Executors.newSingleThreadExecutor(
new ExecutorThreadFactory("KubernetesLeaderElector-ExecutorService"));
Expand Down Expand Up @@ -92,11 +94,20 @@ public KubernetesLeaderElector(
}

public void run() {
executorService.submit(internalLeaderElector::run);
synchronized (lock) {
if (executorService.isShutdown()) {
LOG.debug(
"Ignoring KubernetesLeaderElector.run call because the leader elector has already been shut down.");
} else {
executorService.execute(internalLeaderElector::run);
}
}
}

public void stop() {
executorService.shutdownNow();
synchronized (lock) {
executorService.shutdownNow();
}
}

public static boolean hasLeadership(KubernetesConfigMap configMap, String lockIdentity) {
Expand Down

0 comments on commit fb31e28

Please sign in to comment.