fix(lifecycle): run every shutdown step even when one of them fails (#3472)

EmulatorLifecycle.onStop ran its cleanup steps as one straight sequence. A
RuntimeException from any step skipped everything after it, including the
final storage shutdown, so WAL and hybrid stores were left unflushed and
open whenever a proxy, container or UI manager failed to stop.

Each step now runs in isolation: a failure is logged with its stack trace
and the resource name, the remaining steps still run, and storage shutdown
always runs last. The step order is unchanged.
This commit is contained in:
Niels Kootstra authored and GitHub committed 2026-09-12 13:18:48 -04:00
1 parent 129ba0a260
commit 3bdb019e96
2 files changed
+63 -19

No files matched your search

@@ -443,6 +443,40 @@ class EmulatorLifecycleTest {
inOrder.verify(storageFactory).shutdownAll();
}
@Test
@DisplayName("Should continue cleanup and shut down storage when the initial flush fails")
void shouldContinueCleanupWhenInitialFlushFails() {
doThrow(new IllegalStateException("flush failed")).when(storageFactory).flushAll();
emulatorLifecycle.onStop(Mockito.mock(ShutdownEvent.class));
verify(elastiCacheProxyManager).stopAll();
verify(rdsProxyManager).stopAll();
verify(storageFactory).shutdownAll();
}
@Test
@DisplayName("Should continue cleanup after a middle resource cleanup fails")
void shouldContinueCleanupAfterMiddleResourceFailure() {
doThrow(new IllegalStateException("proxy failed")).when(rdsProxyManager).stopAll();
emulatorLifecycle.onStop(Mockito.mock(ShutdownEvent.class));
verify(memoryDbProxyManager).stopAll();
verify(neptuneProxyManager).stopAll();
verify(storageFactory).shutdownAll();
}
@Test
@DisplayName("Should shut down storage when a late resource cleanup fails")
void shouldShutDownStorageAfterLateResourceFailure() {
doThrow(new IllegalStateException("UI shutdown failed")).when(flociUiManager).shutdown();
emulatorLifecycle.onStop(Mockito.mock(ShutdownEvent.class));
verify(storageFactory).shutdownAll();
}
@Test
@DisplayName("Should still run full resource cleanup when a pre-shutdown hook fails")
void shouldRunFullCleanupAfterFailingPreShutdownHook() throws IOException, InterruptedException {