fix(storage): flush persisted state before container teardown on shutdown (#1607)

onStop() flushed storage last, after the slow proxy/container teardown, so a graceful shutdown could be cut off by the SIGTERM grace window before buffered hybrid data was written (e.g. ECS clusters lost across a restart). Flush first; keep shutdownAll() at the end. Adds an EmulatorLifecycle ordering-guard test. Refs #1521.
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-06-26 23:34:52 -05:00
1 parent 47e79b0ff5
commit 5eec726902
2 files changed
+22

No files matched your search

@@ -233,6 +233,12 @@ public class EmulatorLifecycle {
}
void onStop(@Observes ShutdownEvent ignored) {
// Flush persisted state to disk FIRST, before the slow proxy/container teardown below.
// Stopping Docker sidecars (RDS/ElastiCache/etc.) can block long enough to exhaust the
// SIGTERM grace window and trigger SIGKILL; if the flush ran last it would be skipped and
// in-memory (hybrid) data would be lost on an otherwise-graceful shutdown. shutdownAll()
// still runs at the end to stop the flush schedulers and capture any shutdown-time writes.
storageFactory.flushAll();
if (config.services().ec2().enabled() && !config.services().ec2().mock()) {
ec2MetadataServer.stop();
}