mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
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.
This commit is contained in:
1 parent
444e9e8d6a
commit
26eafba246
2 files changed
+26
No files matched your search
@@ -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();
|
||||
|
||||
@@ -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> 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 {
|
||||
|
||||
Reference in new issue
Block a user