mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(lambda): drop dead pooled containers in WarmPool.acquire() before reuse (#610)
This commit is contained in:
1 parent
7592151cb6
commit
9bdcfaf2b1
4 files changed
+116
-2
No files matched your search
+20
@@ -245,6 +245,26 @@ public class ContainerLifecycleManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the container is currently running. A missing container
|
||||
* is treated as not-running; any other Docker error is treated as running
|
||||
* so a transient daemon hiccup does not evict a healthy warm pool.
|
||||
*
|
||||
* @param containerId the container ID to inspect
|
||||
* @return true if the container exists and is reported as running
|
||||
*/
|
||||
public boolean isContainerRunning(String containerId) {
|
||||
try {
|
||||
InspectContainerResponse inspect = dockerClient.inspectContainerCmd(containerId).exec();
|
||||
return Boolean.TRUE.equals(inspect.getState().getRunning());
|
||||
} catch (NotFoundException e) {
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
LOG.warnv("Liveness check failed for container {0}: {1}", containerId, e.getMessage());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the endpoint (host and port) to connect to a specific container port.
|
||||
*
|
||||
|
||||
@@ -103,8 +103,23 @@ public class WarmPool {
|
||||
|
||||
if (!ephemeral) {
|
||||
ArrayDeque<ContainerHandle> queue = pool.computeIfAbsent(fn.getFunctionName(), k -> new ArrayDeque<>());
|
||||
synchronized (queue) {
|
||||
handle = queue.pollFirst();
|
||||
// Skip pooled handles whose container died out-of-band — otherwise the
|
||||
// caller would wait the full Lambda function timeout.
|
||||
while (true) {
|
||||
ContainerHandle candidate;
|
||||
synchronized (queue) {
|
||||
candidate = queue.pollFirst();
|
||||
}
|
||||
if (candidate == null) {
|
||||
break;
|
||||
}
|
||||
if (containerLauncher.isAlive(candidate)) {
|
||||
handle = candidate;
|
||||
break;
|
||||
}
|
||||
LOG.infov("Discarding dead pooled container {0} for function {1}",
|
||||
candidate.getContainerId(), fn.getFunctionName());
|
||||
stopQuietly(candidate);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
@@ -225,6 +225,16 @@ public class ContainerLauncher {
|
||||
lifecycleManager.stopAndRemove(handle.getContainerId(), handle.getLogStream());
|
||||
}
|
||||
|
||||
/**
|
||||
* Probes whether the handle's underlying container is still running.
|
||||
*
|
||||
* @param handle the warm-pool handle to probe
|
||||
* @return true if the container is still running
|
||||
*/
|
||||
public boolean isAlive(ContainerHandle handle) {
|
||||
return lifecycleManager.isContainerRunning(handle.getContainerId());
|
||||
}
|
||||
|
||||
private void copyDirToContainer(DockerClient dockerClient, String containerId,
|
||||
Path sourceDir, String remotePath, String functionName) {
|
||||
try (java.io.PipedOutputStream pos = new java.io.PipedOutputStream();
|
||||
|
||||
Reference in new issue
Block a user