Skip to content

Commit

Permalink
fix: increased timeout for executor service shutdown when sigterm is …
Browse files Browse the repository at this point in the history
…received (#1325)
  • Loading branch information
junfuchen99 authored Sep 29, 2022
1 parent dcf97bc commit 7730b18
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
public class KernelLifecycle {
private static final Logger logger = LogManager.getLogger(KernelLifecycle.class);
private static final int EXECUTOR_SHUTDOWN_TIMEOUT_SECONDS = 30;
private static final int EXECUTOR_SERVICE_SHUTDOWN_TIMEOUT_SECONDS = 5;
// Enum for provision policy will exist in common library package
// This will be done as part of re-provisioning
// TODO: Use the enum from common library when available
Expand Down Expand Up @@ -523,10 +524,14 @@ public void shutdown(int timeoutSeconds) {
logger.atInfo().setEventType("executor-service-shutdown-initiated").log();
});
logger.atInfo().log("Waiting for executors to shutdown");
boolean executorTerminated = executorService.awaitTermination(timeoutSeconds,
TimeUnit.SECONDS);
boolean scheduledExecutorTerminated = scheduledExecutorService.awaitTermination(timeoutSeconds,
TimeUnit.SECONDS);
// when kernel shuts down due to external signal, give some time for executor service to stop so that
// threads are interrupted correctly
int executorServiceShutdownTimeoutSecond =
timeoutSeconds == -1 ? EXECUTOR_SERVICE_SHUTDOWN_TIMEOUT_SECONDS : timeoutSeconds;
boolean executorTerminated =
executorService.awaitTermination(executorServiceShutdownTimeoutSecond, TimeUnit.SECONDS);
boolean scheduledExecutorTerminated =
scheduledExecutorService.awaitTermination(executorServiceShutdownTimeoutSecond, TimeUnit.SECONDS);
logger.atInfo("executor-service-shutdown-complete")
.kv("executor-terminated", executorTerminated)
.kv("scheduled-executor-terminated", scheduledExecutorTerminated).log();
Expand Down

0 comments on commit 7730b18

Please sign in to comment.