fix(memorydb,neptune,docdb): degrade gracefully with no Docker daemon (#2386)

* fix(memorydb,neptune,docdb): degrade gracefully with no Docker daemon

Applies the daemonless degradation pattern (EcrRegistryManager/RdsContainerManager's
tryStart + isDockerReachable seam) to MemoryDB, Neptune and DocumentDB: control-plane
CreateCluster now reaches AWS's documented 'available' steady state with no backing
container when the Docker daemon is unreachable, instead of leaking a raw
SocketException as a 500. Metadata operations (describe, tag, delete) keep working;
only the data-plane connection to the cache/graph/document database stays unavailable
until a daemon appears.

Changed:
- MemoryDbContainerManager, NeptuneContainerManager, DocDbContainerManager: add
  tryStart()/isDockerReachable(), mirroring RdsContainerManager. start() is untouched
  for other callers.
- MemoryDbService.startBackend, NeptuneService.createDbCluster,
  DocDbService.createDbCluster: use tryStart() and proceed with metadata-only state
  (no proxy/container fields, no auth proxy started) when it returns null.

Already done before this change (grepped for tryEnsureStarted|tryStart across
services/ first): ElastiCache (ElastiCacheContainerManager/ElastiCacheMemcachedContainerManager
+ both services) already has this seam — the issue's mention of "elasticache" needing
the fix is stale. EC2 (Ec2ContainerManager) already has an equivalent seam under a
different name (isDockerAvailable()/markContainerlessRunning()); launch, stop, start,
terminate and reboot all already null-check the container id or probe the daemon
before touching Docker, so no EC2 changes were needed.

Left out: dedicated unit tests for EC2's existing daemonless paths (isDockerAvailable,
markContainerlessRunning) — they were already implemented and behaviorally covered by
existing integration tests, and adding manager-level unit tests for the async
executor-based EC2 launch flow is a separable effort from this rollout.

Tests: added tryStart/isDockerReachable unit tests to
{MemoryDb,Neptune,DocDb}ContainerManagerTest (new file for DocDb) covering
daemon-unreachable, genuine-failure and success paths, plus a
createWithoutDockerDaemonStillReachesAvailable service-level test per service
proving control-plane CRUD succeeds and no proxy/container is touched. Existing
tests that stubbed containerManager.start(...) were updated to stub tryStart(...)
to match the new call site.

Refs lex00/floci#44

* test(memorydb,neptune,docdb): log the tolerated teardown IOException

The three new tryStart-reachable tests caught the acceptor socket's
IOException during teardown with only a comment, no log statement,
identically in all three files. Add a debug-level log line per CLAUDE.md's
catch-block rule.
This commit is contained in:
lex00 authored and GitHub committed 2026-08-19 17:17:56 -04:00
1 parent 337dead734
commit 65b22ff01e
12 files changed
+626 -32

No files matched your search

@@ -79,13 +79,25 @@ public class DocDbService {
} else {
String image = config.services().docdb().defaultImage();
LOG.infov("Creating DocDB cluster {0}, image={1}", id, image);
DocDbContainerHandle handle = containerManager.start(id, image, masterUsername, masterPassword);
cluster.setEndpoint(handle.getHost());
cluster.setReaderEndpoint(handle.getHost());
cluster.setPort(handle.getPort());
cluster.setContainerId(handle.getContainerId());
cluster.setContainerHost(handle.getHost());
cluster.setContainerPort(handle.getPort());
// A cluster record is metadata: its identifier, ARN and tags need no Docker, so the
// cluster is created and reaches 'available' even when no daemon is reachable. Only
// connecting to the database needs the container.
DocDbContainerHandle handle = containerManager.tryStart(id, image, masterUsername, masterPassword);
if (handle != null) {
cluster.setEndpoint(handle.getHost());
cluster.setReaderEndpoint(handle.getHost());
cluster.setPort(handle.getPort());
cluster.setContainerId(handle.getContainerId());
cluster.setContainerHost(handle.getHost());
cluster.setContainerPort(handle.getPort());
} else {
cluster.setEndpoint(resolveEndpointHost());
cluster.setReaderEndpoint(resolveEndpointHost());
cluster.setPort(MONGO_PORT);
LOG.warnv("DocDB cluster {0} created without a backing MongoDB container: no "
+ "Docker daemon is reachable. Metadata operations work; connections to "
+ "the cluster do not until a daemon appears.", id);
}
}
clusters.put(id, cluster);
@@ -40,6 +40,7 @@ public class DocDbContainerManager {
private final EmulatorConfig config;
private final RegionResolver regionResolver;
private final Map<String, DocDbContainerHandle> activeContainers = new ConcurrentHashMap<>();
private volatile boolean dockerUnavailableLogged;
@Inject
public DocDbContainerManager(ContainerBuilder containerBuilder,
@@ -56,6 +57,49 @@ public class DocDbContainerManager {
this.regionResolver = regionResolver;
}
/**
* Attempts {@link #start} and reports the backend as unavailable instead of propagating the
* failure, when the cause is that no Docker daemon is reachable from Floci — Floci running
* inside Docker without a mounted socket, or a stopped daemon on the host. A failure raised
* while the daemon <em>is</em> reachable is a genuine container problem and still propagates,
* so nothing changes for a Floci that can start DocumentDB containers.
*
* @return the container handle, or {@code null} when no Docker daemon is reachable
*/
public DocDbContainerHandle tryStart(String clusterId, String image, String masterUsername, String masterPassword) {
try {
DocDbContainerHandle handle = start(clusterId, image, masterUsername, masterPassword);
dockerUnavailableLogged = false;
return handle;
} catch (RuntimeException e) {
if (isDockerReachable()) {
throw e;
}
if (!dockerUnavailableLogged) {
dockerUnavailableLogged = true;
LOG.warnv("No Docker daemon is reachable from Floci ({0}). DocumentDB metadata "
+ "operations keep working and clusters still reach 'available', but they "
+ "have no backing MongoDB container until a daemon becomes reachable.",
e.getMessage());
}
return null;
}
}
/**
* Probes the configured Docker endpoint, which is how a missing daemon is told apart from a
* container that failed for its own reasons.
*/
public boolean isDockerReachable() {
try {
lifecycleManager.getDockerClient().pingCmd().exec();
return true;
} catch (Exception e) {
LOG.debugv("Docker daemon is not reachable: {0}", e.getMessage());
return false;
}
}
public DocDbContainerHandle start(String clusterId, String image, String masterUsername, String masterPassword) {
LOG.infov("Starting DocumentDB container for cluster: {0}", clusterId);
@@ -488,16 +488,27 @@ public class MemoryDbService {
MemoryDbContainerHandle handle = null;
try {
handle = containerManager.start(name, image);
// A cluster record is metadata: its name, endpoint host and proxy port are derived
// from configuration and need no Docker, so the cluster is created and reaches
// 'available' even when no daemon is reachable. Only connecting to the cache needs
// the container.
handle = containerManager.tryStart(name, image);
cluster.setClusterEndpoint(new Endpoint(resolveEndpointHost(), proxyPort));
cluster.setProxyPort(proxyPort);
cluster.setContainerId(handle.getContainerId());
cluster.setContainerHost(handle.getHost());
cluster.setContainerPort(handle.getPort());
proxyManager.startProxy(name, authRequired, proxyPort,
handle.getHost(), handle.getPort(),
(username, secret) -> authenticate(name, username, secret));
if (handle != null) {
cluster.setContainerId(handle.getContainerId());
cluster.setContainerHost(handle.getHost());
cluster.setContainerPort(handle.getPort());
proxyManager.startProxy(name, authRequired, proxyPort,
handle.getHost(), handle.getPort(),
(username, secret) -> authenticate(name, username, secret));
} else {
LOG.warnv("MemoryDB cluster {0} created without a backing container: no Docker "
+ "daemon is reachable. Metadata operations work; connections to the "
+ "cluster do not until a daemon appears.", name);
}
} catch (RuntimeException e) {
LOG.warnv("MemoryDB cluster {0} provisioning failed, rolling back: {1}", name, e.getMessage());
rollbackBackend(name, handle, proxyPort);
@@ -49,6 +49,7 @@ public class MemoryDbContainerManager {
private final EmulatorConfig config;
private final RegionResolver regionResolver;
private final Map<String, MemoryDbContainerHandle> activeContainers = new ConcurrentHashMap<>();
private volatile boolean dockerUnavailableLogged;
@Inject
public MemoryDbContainerManager(ContainerBuilder containerBuilder,
@@ -65,6 +66,49 @@ public class MemoryDbContainerManager {
this.regionResolver = regionResolver;
}
/**
* Attempts {@link #start} and reports the backend as unavailable instead of propagating the
* failure, when the cause is that no Docker daemon is reachable from Floci — Floci running
* inside Docker without a mounted socket, or a stopped daemon on the host. A failure raised
* while the daemon <em>is</em> reachable is a genuine container problem and still propagates,
* so nothing changes for a Floci that can start MemoryDB containers.
*
* @return the container handle, or {@code null} when no Docker daemon is reachable
*/
public MemoryDbContainerHandle tryStart(String clusterName, String image) {
try {
MemoryDbContainerHandle handle = start(clusterName, image);
dockerUnavailableLogged = false;
return handle;
} catch (RuntimeException e) {
if (isDockerReachable()) {
throw e;
}
if (!dockerUnavailableLogged) {
dockerUnavailableLogged = true;
LOG.warnv("No Docker daemon is reachable from Floci ({0}). MemoryDB metadata "
+ "operations keep working and clusters still reach 'available', but they "
+ "have no backing Redis/Valkey container until a daemon becomes reachable.",
e.getMessage());
}
return null;
}
}
/**
* Probes the configured Docker endpoint, which is how a missing daemon is told apart from a
* container that failed for its own reasons.
*/
public boolean isDockerReachable() {
try {
lifecycleManager.getDockerClient().pingCmd().exec();
return true;
} catch (Exception e) {
LOG.debugv("Docker daemon is not reachable: {0}", e.getMessage());
return false;
}
}
public MemoryDbContainerHandle start(String clusterName, String image) {
LOG.infov("Starting MemoryDB backend container for cluster: {0}", clusterName);
@@ -81,7 +81,11 @@ public class NeptuneService {
LOG.infov("Creating Neptune cluster {0} on proxy port {1}, dbType={2}, image={3}",
id, String.valueOf(proxyPort), dbType, image);
handle = containerManager.start(id, image, dbType);
// A cluster record is metadata: its identifier, ARN, endpoint host and proxy port
// are derived from configuration and need no Docker, so the cluster is created and
// reaches 'available' even when no daemon is reachable. Only connecting to the
// graph database needs the container.
handle = containerManager.tryStart(id, image, dbType);
String region = regionResolver.getDefaultRegion();
String endpointHost = resolveEndpointHost();
@@ -99,12 +103,19 @@ public class NeptuneService {
.replace("-", "").substring(0, 24).toUpperCase());
cluster.setCreatedAt(Instant.now());
cluster.setDbClusterMembers(new ArrayList<>());
cluster.setContainerId(handle.getContainerId());
cluster.setContainerHost(handle.getHost());
cluster.setContainerPort(handle.getPort());
cluster.setProxyPort(proxyPort);
proxyManager.startProxy(id, proxyPort, handle.getHost(), handle.getPort());
if (handle != null) {
cluster.setContainerId(handle.getContainerId());
cluster.setContainerHost(handle.getHost());
cluster.setContainerPort(handle.getPort());
proxyManager.startProxy(id, proxyPort, handle.getHost(), handle.getPort());
} else {
LOG.warnv("Neptune cluster {0} created without a backing graph database container: "
+ "no Docker daemon is reachable. Metadata operations work; connections to "
+ "the cluster do not until a daemon appears.", id);
}
clusters.put(id, cluster);
provisioned = true;
@@ -46,6 +46,7 @@ public class NeptuneContainerManager {
private final EmulatorConfig config;
private final RegionResolver regionResolver;
private final Map<String, NeptuneContainerHandle> activeContainers = new ConcurrentHashMap<>();
private volatile boolean dockerUnavailableLogged;
@Inject
public NeptuneContainerManager(ContainerBuilder containerBuilder,
@@ -62,6 +63,49 @@ public class NeptuneContainerManager {
this.regionResolver = regionResolver;
}
/**
* Attempts {@link #start} and reports the backend as unavailable instead of propagating the
* failure, when the cause is that no Docker daemon is reachable from Floci — Floci running
* inside Docker without a mounted socket, or a stopped daemon on the host. A failure raised
* while the daemon <em>is</em> reachable is a genuine container problem and still propagates,
* so nothing changes for a Floci that can start Neptune containers.
*
* @return the container handle, or {@code null} when no Docker daemon is reachable
*/
public NeptuneContainerHandle tryStart(String clusterId, String image, NeptuneDbType dbType) {
try {
NeptuneContainerHandle handle = start(clusterId, image, dbType);
dockerUnavailableLogged = false;
return handle;
} catch (RuntimeException e) {
if (isDockerReachable()) {
throw e;
}
if (!dockerUnavailableLogged) {
dockerUnavailableLogged = true;
LOG.warnv("No Docker daemon is reachable from Floci ({0}). Neptune metadata "
+ "operations keep working and clusters still reach 'available', but they "
+ "have no backing graph database container until a daemon becomes "
+ "reachable.", e.getMessage());
}
return null;
}
}
/**
* Probes the configured Docker endpoint, which is how a missing daemon is told apart from a
* container that failed for its own reasons.
*/
public boolean isDockerReachable() {
try {
lifecycleManager.getDockerClient().pingCmd().exec();
return true;
} catch (Exception e) {
LOG.debugv("Docker daemon is not reachable: {0}", e.getMessage());
return false;
}
}
public NeptuneContainerHandle start(String clusterId, String image, NeptuneDbType dbType) {
LOG.infov("Starting Neptune backend container ({0}) for cluster: {1}", dbType, clusterId);