mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 23:59:27 -05:00
fix(rds): keep instance available when the liveness probe fails (#5070)
Only a definite not-running answer from Docker marks an instance failed. * Fix #4847 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
This commit is contained in:
1 parent
32f01ba13d
commit
97906c09b9
6 files changed
+183
-17
No files matched your search
+19
-10
@@ -950,27 +950,36 @@ public class ContainerLifecycleManager {
|
||||
/**
|
||||
* Returns whether the container is currently running. A missing container is treated as
|
||||
* not-running; any other Docker error (e.g. an inspect timeout under daemon overload) is also
|
||||
* treated as not-running, so a hung/dead container is not reused from the warm pool — a false
|
||||
* treated as not-running, so a hung/dead container is not reused from the warm pool. A false
|
||||
* negative merely triggers a clean cold-start, which is far cheaper than blocking until the
|
||||
* function timeout.
|
||||
* function timeout. Callers that must not act on a failed probe use {@link #probeContainer}.
|
||||
*
|
||||
* @param containerId the container ID to inspect
|
||||
* @return true only if the container exists and is reported as running; false on any error
|
||||
*/
|
||||
public boolean isContainerRunning(String containerId) {
|
||||
return probeContainer(containerId) == ContainerLiveness.RUNNING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Probes the container and tells a definite answer from a failed probe.
|
||||
*
|
||||
* @param containerId the container ID to inspect
|
||||
* @return RUNNING or NOT_RUNNING when Docker answered (a missing container is NOT_RUNNING),
|
||||
* UNKNOWN when the inspect call itself failed
|
||||
*/
|
||||
public ContainerLiveness probeContainer(String containerId) {
|
||||
try {
|
||||
InspectContainerResponse inspect = dockerClient.inspectContainerCmd(containerId).exec();
|
||||
return Boolean.TRUE.equals(inspect.getState().getRunning());
|
||||
return Boolean.TRUE.equals(inspect.getState().getRunning())
|
||||
? ContainerLiveness.RUNNING
|
||||
: ContainerLiveness.NOT_RUNNING;
|
||||
} catch (NotFoundException e) {
|
||||
return false;
|
||||
return ContainerLiveness.NOT_RUNNING;
|
||||
} catch (Exception e) {
|
||||
// Treat an inspect failure/timeout as NOT running. Under Docker-daemon overload,
|
||||
// returning true here caused the warm pool to "reuse" dead/hung containers, so the
|
||||
// invocation blocked until the function timeout (~20-30s) every time. A false
|
||||
// negative merely triggers a clean cold-start, which is far cheaper than a hang.
|
||||
LOG.warnv("Liveness check failed for container {0}; treating as not running: {1}",
|
||||
LOG.warnv("Liveness check failed for container {0}; state unknown: {1}",
|
||||
containerId, e.getMessage());
|
||||
return false;
|
||||
return ContainerLiveness.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package io.github.hectorvent.floci.core.common.docker;
|
||||
|
||||
/**
|
||||
* Outcome of probing a container's liveness through the Docker API.
|
||||
* {@link #UNKNOWN} means the probe itself failed, so nothing is known about the container.
|
||||
*/
|
||||
public enum ContainerLiveness {
|
||||
RUNNING,
|
||||
NOT_RUNNING,
|
||||
UNKNOWN
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.AwsRegions;
|
||||
import io.github.hectorvent.floci.core.common.BackupWindows;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerLiveness;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerStorageHelper;
|
||||
import io.github.hectorvent.floci.core.common.docker.CurrentContainerNetworkResolver;
|
||||
import io.github.hectorvent.floci.core.common.docker.DockerHostResolver;
|
||||
@@ -2685,7 +2686,8 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
|| instance.getContainerId().isBlank()) {
|
||||
return instance;
|
||||
}
|
||||
if (containerManager.isContainerRunning(instance.getContainerId())) {
|
||||
ContainerLiveness liveness = containerManager.probeContainer(instance.getContainerId());
|
||||
if (liveness != ContainerLiveness.NOT_RUNNING) {
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
+10
-5
@@ -10,6 +10,7 @@ import io.github.hectorvent.floci.core.common.docker.ContainerBuilder;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerDetector;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerExec;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerLifecycleManager;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerLiveness;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerStorageHelper;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerLifecycleManager.ContainerInfo;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerLifecycleManager.EndpointInfo;
|
||||
@@ -433,11 +434,15 @@ public class RdsContainerManager implements RdsBackendGate, Resettable {
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns whether a backing RDS container still exists and is running. */
|
||||
public boolean isContainerRunning(String containerId) {
|
||||
return containerId != null
|
||||
&& !containerId.isBlank()
|
||||
&& lifecycleManager.isContainerRunning(containerId);
|
||||
/**
|
||||
* Probes a backing RDS container. UNKNOWN means the Docker probe failed and the container's
|
||||
* state is not known, which is not the same as the container being gone.
|
||||
*/
|
||||
public ContainerLiveness probeContainer(String containerId) {
|
||||
if (containerId == null || containerId.isBlank()) {
|
||||
return ContainerLiveness.NOT_RUNNING;
|
||||
}
|
||||
return lifecycleManager.probeContainer(containerId);
|
||||
}
|
||||
|
||||
/** Returns the retained runtime handle used to persist cleanup identity after a failed start. */
|
||||
|
||||
Reference in new issue
Block a user