Skip to content

Commit 1cbb797

Browse files
tillrohrmannTheodoreLx
authored andcommitted
[hotfix] Do not use ExecutorService.submit since it can swallow exceptions
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.
1 parent f118c08 commit 1cbb797

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

flink-kubernetes/src/main/java/org/apache/flink/kubernetes/kubeclient/resources/KubernetesLeaderElector.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public class KubernetesLeaderElector {
5353
@VisibleForTesting
5454
public static final String LEADER_ANNOTATION_KEY = "control-plane.alpha.kubernetes.io/leader";
5555

56+
private final Object lock = new Object();
57+
5658
private final ExecutorService executorService =
5759
Executors.newSingleThreadExecutor(
5860
new ExecutorThreadFactory("KubernetesLeaderElector-ExecutorService"));
@@ -92,11 +94,20 @@ public KubernetesLeaderElector(
9294
}
9395

9496
public void run() {
95-
executorService.submit(internalLeaderElector::run);
97+
synchronized (lock) {
98+
if (executorService.isShutdown()) {
99+
LOG.debug(
100+
"Ignoring KubernetesLeaderElector.run call because the leader elector has already been shut down.");
101+
} else {
102+
executorService.execute(internalLeaderElector::run);
103+
}
104+
}
96105
}
97106

98107
public void stop() {
99-
executorService.shutdownNow();
108+
synchronized (lock) {
109+
executorService.shutdownNow();
110+
}
100111
}
101112

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

0 commit comments

Comments
 (0)