From 26eafba246668bb5604a75b41bdf95d64fde59da Mon Sep 17 00:00:00 2001 From: Niels Kootstra <545768+nkootstra@users.noreply.github.com> Date: Fri, 25 Sep 2026 21:09:53 +0200 Subject: [PATCH] fix(lifecycle): exit when startup is interrupted (#4420) The InterruptedException branch in onHttpStart restored the interrupt flag and logged, but never called Quarkus.asyncExit() like the other startup failure branch does. An interrupted startup hook left the process half-started instead of exiting. --- .../floci/lifecycle/EmulatorLifecycle.java | 1 + .../lifecycle/EmulatorLifecycleTest.java | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/main/java/io/github/hectorvent/floci/lifecycle/EmulatorLifecycle.java b/src/main/java/io/github/hectorvent/floci/lifecycle/EmulatorLifecycle.java index 096f379f8d..18f5c57161 100644 --- a/src/main/java/io/github/hectorvent/floci/lifecycle/EmulatorLifecycle.java +++ b/src/main/java/io/github/hectorvent/floci/lifecycle/EmulatorLifecycle.java @@ -284,6 +284,7 @@ public class EmulatorLifecycle { } catch (InterruptedException e) { Thread.currentThread().interrupt(); LOG.error("Startup hook execution interrupted — shutting down", e); + Quarkus.asyncExit(); } catch (Exception e) { LOG.error("Startup hook execution failed — shutting down", e); Quarkus.asyncExit(); diff --git a/src/test/java/io/github/hectorvent/floci/lifecycle/EmulatorLifecycleTest.java b/src/test/java/io/github/hectorvent/floci/lifecycle/EmulatorLifecycleTest.java index 4a7d6ee7cf..51add00aae 100644 --- a/src/test/java/io/github/hectorvent/floci/lifecycle/EmulatorLifecycleTest.java +++ b/src/test/java/io/github/hectorvent/floci/lifecycle/EmulatorLifecycleTest.java @@ -29,6 +29,7 @@ import io.github.hectorvent.floci.services.rds.container.RdsContainerManager; import io.github.hectorvent.floci.services.rds.proxy.RdsProxyManager; import io.github.hectorvent.floci.services.stepfunctions.StepFunctionsService; import io.github.hectorvent.floci.services.timestreaminfluxdb.TimestreamInfluxDbService; +import io.quarkus.runtime.Quarkus; import io.quarkus.runtime.ShutdownDelayInitiatedEvent; import io.quarkus.runtime.ShutdownEvent; import io.quarkus.runtime.StartupEvent; @@ -41,6 +42,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InOrder; import org.mockito.Mock; +import org.mockito.MockedStatic; import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; @@ -385,6 +387,29 @@ class EmulatorLifecycleTest { verify(initLifecycleState, never()).markStartCompleted(); } + @Test + @DisplayName("onHttpStart exits the process when a startup hook is interrupted") + void onHttpStart_hookInterrupted_exitsProcess() throws IOException, InterruptedException { + when(tlsConfig.enabled()).thenReturn(false); + when(initializationHooksRunner.hasHooks(InitializationHook.START)).thenReturn(true); + when(initializationHooksRunner.hasHooks(InitializationHook.READY)).thenReturn(false); + doThrow(new InterruptedException("interrupted")) + .when(initializationHooksRunner).run(InitializationHook.START); + + Thread.interrupted(); + try (MockedStatic quarkus = Mockito.mockStatic(Quarkus.class)) { + try { + emulatorLifecycle.onHttpStart(new HttpServerStart(new HttpServerOptions().setPort(4566))); + + assertTrue(Thread.currentThread().isInterrupted(), + "Interrupt flag must be restored so the JVM sees the request to stop"); + } finally { + Thread.interrupted(); + } + quarkus.verify(Quarkus::asyncExit); + } + } + @Test @DisplayName("Should run shutdown hooks in the pre-shutdown phase, before the HTTP server stops") void shouldRunShutdownHooksInPreShutdownPhase() throws IOException, InterruptedException {