Skip to content

Commit 7730b18

Browse files
authored
fix: increased timeout for executor service shutdown when sigterm is received (#1325)
1 parent dcf97bc commit 7730b18

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/main/java/com/aws/greengrass/lifecyclemanager/KernelLifecycle.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
public class KernelLifecycle {
8383
private static final Logger logger = LogManager.getLogger(KernelLifecycle.class);
8484
private static final int EXECUTOR_SHUTDOWN_TIMEOUT_SECONDS = 30;
85+
private static final int EXECUTOR_SERVICE_SHUTDOWN_TIMEOUT_SECONDS = 5;
8586
// Enum for provision policy will exist in common library package
8687
// This will be done as part of re-provisioning
8788
// TODO: Use the enum from common library when available
@@ -523,10 +524,14 @@ public void shutdown(int timeoutSeconds) {
523524
logger.atInfo().setEventType("executor-service-shutdown-initiated").log();
524525
});
525526
logger.atInfo().log("Waiting for executors to shutdown");
526-
boolean executorTerminated = executorService.awaitTermination(timeoutSeconds,
527-
TimeUnit.SECONDS);
528-
boolean scheduledExecutorTerminated = scheduledExecutorService.awaitTermination(timeoutSeconds,
529-
TimeUnit.SECONDS);
527+
// when kernel shuts down due to external signal, give some time for executor service to stop so that
528+
// threads are interrupted correctly
529+
int executorServiceShutdownTimeoutSecond =
530+
timeoutSeconds == -1 ? EXECUTOR_SERVICE_SHUTDOWN_TIMEOUT_SECONDS : timeoutSeconds;
531+
boolean executorTerminated =
532+
executorService.awaitTermination(executorServiceShutdownTimeoutSecond, TimeUnit.SECONDS);
533+
boolean scheduledExecutorTerminated =
534+
scheduledExecutorService.awaitTermination(executorServiceShutdownTimeoutSecond, TimeUnit.SECONDS);
530535
logger.atInfo("executor-service-shutdown-complete")
531536
.kv("executor-terminated", executorTerminated)
532537
.kv("scheduled-executor-terminated", scheduledExecutorTerminated).log();

0 commit comments

Comments
 (0)