diff --git a/docs/configuration/advanced/application-yml.md b/docs/configuration/advanced/application-yml.md index 5b63adeb79..46f84fd9e9 100644 --- a/docs/configuration/advanced/application-yml.md +++ b/docs/configuration/advanced/application-yml.md @@ -120,8 +120,8 @@ floci: log-max-size: "10m" # Max size per container log file before rotation log-max-file: "3" # Number of rotated log files to retain docker-host: unix:///var/run/docker.sock # Docker daemon socket (shared by Lambda, RDS, ElastiCache) - max-connections: 1024 # Docker client connection pool; each live Lambda container holds 1 - streaming-max-connections: 512 # Separate pool for container log-follow streams + max-connections: 1024 # Docker client connection pool for short calls + streaming-max-connections: 2048 # Separate pool for streams; each live Lambda container holds 2, plus 1 per extension docker-config-path: "" # Path to dir containing Docker's config.json (e.g. /root/.docker) registry-credentials: [] # Per-registry explicit credentials for private registries diff --git a/docs/configuration/docker.md b/docs/configuration/docker.md index 4c0d4b2288..69022c1206 100644 --- a/docs/configuration/docker.md +++ b/docs/configuration/docker.md @@ -52,9 +52,9 @@ The entrypoint needs to start as root to read the socket's group and to honour t ## Connection Pool -Every Docker call Floci makes goes through one shared client with a bounded connection pool. Some of those connections stay open for as long as a container runs: each Lambda container holds one (the watcher that notices its runtime exiting) plus one per Lambda extension. Log-follow streams use a second pool, described below. When those long-lived connections fill the pool, every other Docker call (create, start, stop, remove) waits for one to free up, and Floci stops making progress. +Floci's short Docker calls (create, start, stop, remove and the like) go through one client with a bounded connection pool. A few streams also hold a connection from it for as long as they run: CodeBuild phase commands, EKS audit log followers and ECS Exec sessions. When long-lived connections fill the pool, every other Docker call waits for one to free up, and Floci stops making progress. -The default of 1024 connections covers the 500 concurrent Lambda containers the default [Runtime API port range](../services/lambda.md#configuration) allows. Raise it if you widen that range or run many other containers at the same time: +The default is 1024 connections. Raise it if you run many CodeBuild builds or ECS Exec sessions at the same time: ```yaml floci: @@ -64,12 +64,12 @@ floci: Environment variable: `FLOCI_DOCKER_MAX_CONNECTIONS` -Container log-follow streams use a second, separate pool so they can never starve create, start, stop and remove calls. Its size defaults to 512 and follows the same rule (at least 1). Exec-output and container-wait streams (CodeBuild phases, Lambda extensions and exit watchers, EKS audit followers) still use the main pool and count against `max-connections`: +Streams that stay open for as long as a container runs use a second, separate pool, so they can never starve create, start, stop and remove calls. Each Lambda container holds two of these (its log stream and the watcher that notices its runtime exiting) plus one per Lambda extension, and other containers' log streams use it too. The default of 2048 covers the 500 concurrent Lambda containers the default [Runtime API port range](../services/lambda.md#configuration) allows, with two extensions each. Raise it if you widen that range or run many other containers at the same time. It follows the same rule (at least 1): ```yaml floci: docker: - streaming-max-connections: 512 + streaming-max-connections: 2048 ``` Environment variable: `FLOCI_DOCKER_STREAMING_MAX_CONNECTIONS` @@ -349,7 +349,8 @@ caller keeps its existing failure handling after retries are exhausted. |---|---|---| | `FLOCI_DOCKER_DOCKER_HOST` | `unix:///var/run/docker.sock` | Docker daemon socket | | `FLOCI_DOCKER_DOCKER_CONFIG_PATH` | _(unset)_ | Path to directory containing Docker's `config.json` | -| `FLOCI_DOCKER_MAX_CONNECTIONS` | `1024` | Connection pool size for Floci's Docker client. Each live Lambda container holds two connections, so about half this many can run at once | +| `FLOCI_DOCKER_MAX_CONNECTIONS` | `1024` | Connection pool size for Floci's short Docker calls, plus CodeBuild phase commands, EKS audit log followers and ECS Exec sessions | +| `FLOCI_DOCKER_STREAMING_MAX_CONNECTIONS` | `2048` | Connection pool size for streams that last a container's lifetime. Each live Lambda container holds two (log stream and exit watcher) plus one per extension | | `FLOCI_DOCKER_REGISTRY_CREDENTIALS_0__SERVER` | _(unset)_ | Registry hostname for credential entry 0 | | `FLOCI_DOCKER_REGISTRY_CREDENTIALS_0__USERNAME` | _(unset)_ | Username for credential entry 0 | | `FLOCI_DOCKER_REGISTRY_CREDENTIALS_0__PASSWORD` | _(unset)_ | Password for credential entry 0 | diff --git a/docs/configuration/environment-variables.md b/docs/configuration/environment-variables.md index 1f93c5e7f6..ccd53079b7 100644 --- a/docs/configuration/environment-variables.md +++ b/docs/configuration/environment-variables.md @@ -117,8 +117,8 @@ This foundation release provides opt-in security-group filtering for EC2 Docker | `FLOCI_NETWORK_SECURITY_GROUP_ENFORCEMENT_HELPER_IMAGE` | `floci/network-helper:local` | Linux helper image containing nftables; Floci builds the default image locally when missing | | `FLOCI_DOCKER_DOCKER_HOST` | `unix:///var/run/docker.sock` | Docker daemon socket path or TCP address | | `FLOCI_DOCKER_DOCKER_CONFIG_PATH` | _(none)_ | Path to a directory containing Docker's `config.json` for registry auth | -| `FLOCI_DOCKER_MAX_CONNECTIONS` | `1024` | Connection pool size for Floci's Docker client. Each live Lambda container holds one connection (its exit watcher) plus one per extension; log streams use the streaming pool. See [Docker Configuration](docker.md#connection-pool) | -| `FLOCI_DOCKER_STREAMING_MAX_CONNECTIONS` | `512` | Connection pool size for container log-follow streams, kept apart from the main pool so they never starve create, start, stop and remove. See [Docker Configuration](docker.md#connection-pool) | +| `FLOCI_DOCKER_MAX_CONNECTIONS` | `1024` | Connection pool size for Floci's short Docker calls, plus CodeBuild phase commands, EKS audit log followers and ECS Exec sessions. See [Docker Configuration](docker.md#connection-pool) | +| `FLOCI_DOCKER_STREAMING_MAX_CONNECTIONS` | `2048` | Connection pool size for streams that last a container's lifetime, kept apart from the main pool so they never starve create, start, stop and remove. Each live Lambda container holds two (log stream and exit watcher) plus one per extension. See [Docker Configuration](docker.md#connection-pool) | | `FLOCI_DOCKER_IMAGE_REGISTRY_BASE` | _(none)_ | Optional registry/repository base for every Docker image Floci launches. When set, `postgres:16-alpine` resolves as `/postgres:16-alpine` and `public.ecr.aws/docker/library/ubuntu:24.04` resolves as `/public.ecr.aws/docker/library/ubuntu:24.04`. An image in a registry on `localhost` or a loopback address, Floci's own ECR among them, is launched as it is | | `FLOCI_DOCKER_LOG_MAX_SIZE` | `10m` | Log rotation max size for spawned containers (e.g. `10m`, `1g`) | | `FLOCI_DOCKER_LOG_MAX_FILE` | `3` | Number of rotated log files to keep for spawned containers | diff --git a/docs/services/lambda.md b/docs/services/lambda.md index 96447b5479..f99c19831d 100644 --- a/docs/services/lambda.md +++ b/docs/services/lambda.md @@ -673,7 +673,7 @@ Configuration resource reads and `ListFunctionsByCodeSigningConfig` return | `FLOCI_SERVICES_LAMBDA_DURABLE_SWEEP_ENABLED` | `true` | Fire durable execution timers (waits, step retries, execution timeouts, retention expiry) | | `FLOCI_SERVICES_LAMBDA_DURABLE_SWEEP_INTERVAL_SECONDS` | `1` | How often the durable sweep runs | | `FLOCI_SERVICES_LAMBDA_RUNTIME_API_BASE_PORT` | `12000` | First port in the Lambda Runtime API range | -| `FLOCI_SERVICES_LAMBDA_RUNTIME_API_MAX_PORT` | `12499` | Last port in the Lambda Runtime API range. One port is held per running container, so the range width caps concurrent executions. Each running container also holds two Docker connections, so a wider range needs a matching `FLOCI_DOCKER_MAX_CONNECTIONS` | +| `FLOCI_SERVICES_LAMBDA_RUNTIME_API_MAX_PORT` | `12499` | Last port in the Lambda Runtime API range. One port is held per running container, so the range width caps concurrent executions. Each running container also holds two streaming Docker connections plus one per extension, so a wider range needs a matching `FLOCI_DOCKER_STREAMING_MAX_CONNECTIONS` | | `FLOCI_SERVICES_LAMBDA_CODE_PATH` | `./data/lambda-code` | Directory where Lambda ZIP files are stored | | `FLOCI_SERVICES_LAMBDA_POLL_INTERVAL_MS` | `1000` | Event-source mapping poll interval (milliseconds) | | `FLOCI_SERVICES_LAMBDA_ASYNC_RETRY_DELAY_SECONDS` | `60` | Wait before the first retry of a failed asynchronous invocation (seconds); the second waits twice this, `0` retries back to back | diff --git a/src/main/java/io/floci/aws/config/EmulatorConfig.java b/src/main/java/io/floci/aws/config/EmulatorConfig.java index f07e40958b..7f7ebaf9c1 100644 --- a/src/main/java/io/floci/aws/config/EmulatorConfig.java +++ b/src/main/java/io/floci/aws/config/EmulatorConfig.java @@ -4152,30 +4152,33 @@ public interface EmulatorConfig { String dockerHost(); /** - * Size of the connection pool behind the shared Docker client. Every Docker call leases a - * connection from it, and some hold one for as long as a container runs: a Lambda - * container holds one (its exit watcher) plus one per extension. Log-follow streams - * live in the separate streaming pool. Once the long-lived connections fill this pool, - * create, start, stop and remove wait for a free connection, including the calls that - * would release one, so the emulator stalls. + * Size of the connection pool behind the shared Docker client. Every short Docker call + * leases a connection from it, and a few streams hold one for as long as they run: + * CodeBuild phase execs, EKS audit followers and ECS Exec sessions. The streams a Lambda + * container holds for its whole lifetime live in the separate streaming pool. Once + * long-lived connections fill this pool, create, start, stop and remove wait for a free + * connection, including the calls that would release one, so the emulator stalls. * - *

1024 rather than the former hard-coded 100, which capped live Lambda containers at - * about 50: a tenth of the 500 that the runtime API port range - * ({@link LambdaServiceConfig#runtimeApiBasePort}) exists to allow. Connections are - * opened on demand, so a small stack never approaches the limit. + *

1024 rather than the former hard-coded 100. Connections are opened on demand, so a + * small stack never approaches the limit. */ @WithDefault("1024") int maxConnections(); /** * Connection pool size for the {@code @StreamingDocker} DockerClient, sized for the - * long-lived container log-follow streams that occupy a slot for a container's entire - * lifetime. Exec-output and container-wait streams stay on the main pool. Total live - * containers is unbounded across distinct functions (each {@code WarmPool} caps only - * per-function), so this pool is sized generously rather than tied to any single - * function's warm-pool cap. + * long-lived streams that occupy a slot for a container's entire lifetime: container log + * follow, and for each Lambda container its exit watcher and one exec per extension. + * Total live containers is unbounded across distinct functions (each {@code WarmPool} + * caps only per-function), so this pool is sized generously rather than tied to any + * single function's warm-pool cap. + * + *

2048 covers the 500 containers the runtime API port range + * ({@link LambdaServiceConfig#runtimeApiBasePort}) allows, each with its log follow, its + * exit watcher and two extensions. Connections are opened on demand, so a small stack + * never approaches the limit. */ - @WithDefault("512") + @WithDefault("2048") int streamingMaxConnections(); /** diff --git a/src/main/java/io/floci/aws/core/common/docker/ContainerLifecycleManager.java b/src/main/java/io/floci/aws/core/common/docker/ContainerLifecycleManager.java index 950a9bf00d..9a940e6e00 100644 --- a/src/main/java/io/floci/aws/core/common/docker/ContainerLifecycleManager.java +++ b/src/main/java/io/floci/aws/core/common/docker/ContainerLifecycleManager.java @@ -1500,8 +1500,9 @@ public class ContainerLifecycleManager { } /** - * Returns the underlying DockerClient for operations not covered by this manager. - * Prefer using manager methods when available. + * Returns the underlying control-plane DockerClient for operations not covered by this + * manager. Prefer using manager methods when available. A stream that stays open for a + * container's lifetime belongs on the {@link StreamingDocker} client instead. */ public DockerClient getDockerClient() { return dockerClient; diff --git a/src/main/java/io/floci/aws/core/common/docker/DockerClientProducer.java b/src/main/java/io/floci/aws/core/common/docker/DockerClientProducer.java index d0b7835186..c33a271c65 100644 --- a/src/main/java/io/floci/aws/core/common/docker/DockerClientProducer.java +++ b/src/main/java/io/floci/aws/core/common/docker/DockerClientProducer.java @@ -424,10 +424,9 @@ public class DockerClientProducer { /** * Control-plane DockerClient: create/start/stop/remove/copyArchive and every other * short-lived call in Floci. Kept on its own connection pool, separate from the - * {@link StreamingDocker} bean, so long-lived log-follow streams can never occupy every - * lease in this pool and starve these short calls until httpclient5's connection-request - * timeout fires. Exec-output and container-wait streams (CodeBuild phases, Lambda - * extensions and exit watchers, EKS audit followers) still use this pool. + * {@link StreamingDocker} bean, so long-lived streams can never occupy every lease in this + * pool and starve these short calls until httpclient5's connection-request timeout fires. + * CodeBuild phase execs, EKS audit followers and ECS Exec sessions still use this pool. */ @Produces @ApplicationScoped @@ -437,7 +436,8 @@ public class DockerClientProducer { } /** - * Streaming DockerClient: container log-follow ({@link ContainerLogStreamer}). Each + * Streaming DockerClient: container log-follow ({@link ContainerLogStreamer}), Lambda + * extension execs and Lambda exit watchers, and Lambda Web attach streams. Each * stream occupies a connection pool slot for its entire lifetime, so sharing the * control-plane pool meant a fan-out of many concurrent streams exhausted it and blocked * control-plane calls. Sized separately because {@code WarmPool}'s cap is per-function, @@ -519,14 +519,14 @@ public class DockerClientProducer { /** * Wraps the control-plane transport in {@link RetryingDockerHttpClient} so every short-lived - * docker call survives a transient socket drop; the streaming transport stays unwrapped, - * its requests (log-follow, exec output) hold hijacked or long-lived streams that must never - * be replayed, and its exec-start calls are the one request retrying could turn into a - * re-run command. + * docker call survives a transient socket drop. The streaming transport replays only container + * waits, as the control-plane one does: its other requests (log follow, attach, exec output) + * hold hijacked or long-lived streams that must never be replayed, and its exec-start calls are + * the one request retrying could turn into a re-run command. */ static DockerHttpClient wrapForRole(DockerHttpClient transport, String role) { if (!"control-plane".equals(role)) { - return transport; + return RetryingDockerHttpClient.forContainerWaits(transport); } LOG.info("Wrapping control-plane docker transport in transient-I/O retry"); return new RetryingDockerHttpClient(transport); diff --git a/src/main/java/io/floci/aws/core/common/docker/RetryingDockerHttpClient.java b/src/main/java/io/floci/aws/core/common/docker/RetryingDockerHttpClient.java index 4e10e8850d..9a40a9b836 100644 --- a/src/main/java/io/floci/aws/core/common/docker/RetryingDockerHttpClient.java +++ b/src/main/java/io/floci/aws/core/common/docker/RetryingDockerHttpClient.java @@ -6,6 +6,7 @@ import com.github.dockerjava.transport.DockerHttpClient; import org.jboss.logging.Logger; import java.io.IOException; +import java.util.function.Predicate; /** * Decorates a {@link DockerHttpClient} with the {@link DockerRetry} policy so every docker call @@ -65,20 +66,43 @@ public final class RetryingDockerHttpClient implements DockerHttpClient { private final DockerHttpClient delegate; private final int maxAttempts; private final long backoffMillis; + private final Predicate replayable; public RetryingDockerHttpClient(DockerHttpClient delegate) { this(delegate, MAX_ATTEMPTS, BACKOFF_MS); } RetryingDockerHttpClient(DockerHttpClient delegate, int maxAttempts, long backoffMillis) { + this(delegate, maxAttempts, backoffMillis, RetryingDockerHttpClient::isReplayable); + } + + private RetryingDockerHttpClient(DockerHttpClient delegate, int maxAttempts, long backoffMillis, + Predicate replayable) { this.delegate = delegate; this.maxAttempts = maxAttempts; this.backoffMillis = backoffMillis; + this.replayable = replayable; + } + + /** + * A decorator that replays only container waits, for the streaming transport. A wait that fails + * before the daemon answers is replayed as it is on the control-plane transport, while the + * streaming transport's other requests, exec starts and log and attach streams, are never + * replayed. + */ + static RetryingDockerHttpClient forContainerWaits(DockerHttpClient delegate) { + return forContainerWaits(delegate, MAX_ATTEMPTS, BACKOFF_MS); + } + + static RetryingDockerHttpClient forContainerWaits(DockerHttpClient delegate, int maxAttempts, + long backoffMillis) { + return new RetryingDockerHttpClient(delegate, maxAttempts, backoffMillis, + request -> isReplayable(request) && isContainerWait(request)); } @Override public Response execute(Request request) { - if (!isReplayable(request)) { + if (!replayable.test(request)) { return delegate.execute(request); } return DockerRetry.call(maxAttempts, backoffMillis, () -> delegate.execute(request)); @@ -110,10 +134,9 @@ public final class RetryingDockerHttpClient implements DockerHttpClient { /** The {@code POST} routes whose replay after a lost response leaves the same outcome. */ private static boolean isReplayablePost(Request request) { String path = request.path(); - int queryStart = path.indexOf('?'); - String route = queryStart < 0 ? path : path.substring(0, queryStart); + String route = route(path); if (route.endsWith("/containers/create")) { - String query = queryStart < 0 ? "" : path.substring(queryStart + 1); + String query = route.length() < path.length() ? path.substring(route.length() + 1) : ""; for (String param : query.split("&")) { if (param.startsWith("name=")) { return true; @@ -128,6 +151,16 @@ public final class RetryingDockerHttpClient implements DockerHttpClient { || route.endsWith("/images/create"); } + private static boolean isContainerWait(Request request) { + return "POST".equals(request.method()) && route(request.path()).endsWith("/wait"); + } + + /** A request path without its query string. */ + private static String route(String path) { + int queryStart = path.indexOf('?'); + return queryStart < 0 ? path : path.substring(0, queryStart); + } + /** * Whether a volume create names its volume. A replayed named create returns the existing * volume; a replayed unnamed one makes a second volume and orphans the first. diff --git a/src/main/java/io/floci/aws/core/common/docker/StreamingDocker.java b/src/main/java/io/floci/aws/core/common/docker/StreamingDocker.java index 44639ffa2f..d5c1ea80f4 100644 --- a/src/main/java/io/floci/aws/core/common/docker/StreamingDocker.java +++ b/src/main/java/io/floci/aws/core/common/docker/StreamingDocker.java @@ -8,9 +8,9 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** - * CDI qualifier for the DockerClient dedicated to long-lived streaming operations, - * container log-follow ({@link ContainerLogStreamer}). Exec-output and container-wait - * streams still use the control-plane client. These calls occupy a connection pool + * CDI qualifier for the DockerClient dedicated to long-lived streaming operations: + * container log-follow ({@link ContainerLogStreamer}), Lambda extension execs and exit + * watchers, and Lambda Web attach streams. These calls occupy a connection pool * slot for a container's entire lifetime, so they must not share a pool * with short-lived control-plane calls (create/start/stop/remove/copyArchive): a fan-out * of many long-lived streams would otherwise starve the control-plane calls out of a diff --git a/src/main/java/io/floci/aws/services/lambda/launcher/ContainerLauncher.java b/src/main/java/io/floci/aws/services/lambda/launcher/ContainerLauncher.java index 2267b61767..9110825885 100644 --- a/src/main/java/io/floci/aws/services/lambda/launcher/ContainerLauncher.java +++ b/src/main/java/io/floci/aws/services/lambda/launcher/ContainerLauncher.java @@ -16,6 +16,7 @@ import io.floci.aws.core.common.docker.DockerHostResolver; import io.floci.aws.core.common.docker.DockerPlatforms; import io.floci.aws.core.common.docker.LaunchedContainerAwsEnv; import io.floci.aws.core.common.docker.RetryingTarCopier; +import io.floci.aws.core.common.docker.StreamingDocker; import io.floci.aws.services.ec2.Ec2Service; import io.floci.aws.services.ecr.registry.EcrRegistryManager; import io.floci.aws.services.iam.model.SessionCreds; @@ -119,6 +120,7 @@ public class ContainerLauncher implements LambdaRuntimeLauncher { private final ContainerBuilder containerBuilder; private final ContainerLifecycleManager lifecycleManager; + private final DockerClient streamingDocker; private final ContainerLogStreamer logStreamer; private final ImageResolver imageResolver; private final RuntimeApiServerFactory runtimeApiServerFactory; @@ -136,6 +138,7 @@ public class ContainerLauncher implements LambdaRuntimeLauncher { @Inject public ContainerLauncher(ContainerBuilder containerBuilder, ContainerLifecycleManager lifecycleManager, + @StreamingDocker DockerClient streamingDocker, ContainerLogStreamer logStreamer, ImageResolver imageResolver, RuntimeApiServerFactory runtimeApiServerFactory, @@ -148,6 +151,7 @@ public class ContainerLauncher implements LambdaRuntimeLauncher { Ec2Service ec2Service) { this.containerBuilder = containerBuilder; this.lifecycleManager = lifecycleManager; + this.streamingDocker = streamingDocker; this.logStreamer = logStreamer; this.imageResolver = imageResolver; this.runtimeApiServerFactory = runtimeApiServerFactory; @@ -1469,7 +1473,8 @@ public class ContainerLauncher implements LambdaRuntimeLauncher { */ private void watchForUnexpectedExit(DockerClient dockerClient, String containerId, RuntimeApiServer runtimeApiServer) { - LambdaExitWatcher.watch(dockerClient, containerId, runtimeApiServer::handleRuntimeProcessExited); + LambdaExitWatcher.watch(dockerClient, streamingDocker, containerId, + runtimeApiServer::handleRuntimeProcessExited); } private void launchExtensions(DockerClient dockerClient, String containerId, String functionName, @@ -1496,7 +1501,10 @@ public class ContainerLauncher implements LambdaRuntimeLauncher { // the container log and an observability extension's output would vanish entirely. // Draining is also required in its own right — an unread exec pipe fills up and // stalls the extension process. - dockerClient.execStartCmd(execId).exec(logStreamer.execLogCallbackForAccount( + // + // The stream holds its connection while the extension runs, so it uses the + // streaming pool, where it cannot starve short control-plane calls. + streamingDocker.execStartCmd(execId).exec(logStreamer.execLogCallbackForAccount( logDestination.accountId(), logDestination.logGroup(), logDestination.logStream(), logDestination.region(), "lambda:" + functionName + ":" + name)); diff --git a/src/main/java/io/floci/aws/services/lambda/launcher/LambdaExitWatcher.java b/src/main/java/io/floci/aws/services/lambda/launcher/LambdaExitWatcher.java index 392e475f2a..eb8786845a 100644 --- a/src/main/java/io/floci/aws/services/lambda/launcher/LambdaExitWatcher.java +++ b/src/main/java/io/floci/aws/services/lambda/launcher/LambdaExitWatcher.java @@ -29,6 +29,9 @@ import java.util.function.LongSupplier; * time, so the watch outlasts a short outage instead of spending its attempts within milliseconds; after * {@link #MAX_QUICK_FAILURES} in a row it stops. A stream that lived longer than {@link #QUICK_FAILURE} * resets the count and re-arms at once. + * + *

The wait stream holds its connection for the container's whole lifetime, so it runs on the + * streaming client; the inspect is a short call and stays on the control-plane client. */ final class LambdaExitWatcher { @@ -42,15 +45,17 @@ final class LambdaExitWatcher { static final Duration FIRST_RETRY_DELAY = Duration.ofSeconds(1); private final DockerClient dockerClient; + private final DockerClient streamingDocker; private final String containerId; private final IntConsumer onExit; private final BiConsumer scheduler; private final LongSupplier nanoClock; private int quickFailures; - LambdaExitWatcher(DockerClient dockerClient, String containerId, IntConsumer onExit, - BiConsumer scheduler, LongSupplier nanoClock) { + LambdaExitWatcher(DockerClient dockerClient, DockerClient streamingDocker, String containerId, + IntConsumer onExit, BiConsumer scheduler, LongSupplier nanoClock) { this.dockerClient = dockerClient; + this.streamingDocker = streamingDocker; this.containerId = containerId; this.onExit = onExit; this.scheduler = scheduler; @@ -58,9 +63,10 @@ final class LambdaExitWatcher { } /** Arms a watch that calls {@code onExit} with the exit status, at most once per exit. */ - static void watch(DockerClient dockerClient, String containerId, IntConsumer onExit) { - new LambdaExitWatcher(dockerClient, containerId, onExit, LambdaExitWatcher::schedule, System::nanoTime) - .arm(); + static void watch(DockerClient dockerClient, DockerClient streamingDocker, String containerId, + IntConsumer onExit) { + new LambdaExitWatcher(dockerClient, streamingDocker, containerId, onExit, LambdaExitWatcher::schedule, + System::nanoTime).arm(); } private static void schedule(Duration delay, Runnable task) { @@ -70,7 +76,7 @@ final class LambdaExitWatcher { void arm() { long armedAt = nanoClock.getAsLong(); try { - dockerClient.waitContainerCmd(containerId).exec(new WaitContainerResultCallback() { + streamingDocker.waitContainerCmd(containerId).exec(new WaitContainerResultCallback() { @Override public void onNext(WaitResponse response) { super.onNext(response); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 6b64c6bee6..12e5feb86b 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -382,17 +382,18 @@ floci: log-max-size: "10m" log-max-file: "3" docker-host: unix:///var/run/docker.sock - # FLOCI_DOCKER_MAX_CONNECTIONS: connection pool size for every Docker call Floci makes. Each - # live Lambda container holds 1 connection for its whole lifetime (its exit watcher) plus one - # per extension; log follow uses the streaming pool below. Past the limit, - # create/start/stop/remove wait for a free connection and the emulator stalls. 1024 covers - # the 500 containers the runtime API port range allows. Keep in step with the @WithDefault on - # EmulatorConfig.DockerConfig.maxConnections: a value set here WINS over the annotation. + # FLOCI_DOCKER_MAX_CONNECTIONS: connection pool size for Floci's short Docker calls, plus + # CodeBuild phase execs, EKS audit followers and ECS Exec sessions. Past the limit, + # create/start/stop/remove wait for a free connection and the emulator stalls. Keep in step + # with the @WithDefault on EmulatorConfig.DockerConfig.maxConnections: a value set here WINS + # over the annotation. max-connections: 1024 - # FLOCI_DOCKER_STREAMING_MAX_CONNECTIONS: separate pool for container log-follow streams, so - # they never starve create/start/stop/remove. Keep in step with the @WithDefault on + # FLOCI_DOCKER_STREAMING_MAX_CONNECTIONS: separate pool for streams that last a container's + # lifetime, so they never starve create/start/stop/remove. Each live Lambda container holds 2 + # (log follow and exit watcher) plus one per extension; 2048 covers the 500 containers the + # runtime API port range allows with two extensions each. Keep in step with the @WithDefault on # EmulatorConfig.DockerConfig.streamingMaxConnections: a value set here WINS over the annotation. - streaming-max-connections: 512 + streaming-max-connections: 2048 # FLOCI_DOCKER_CONNECTION_REQUEST_TIMEOUT_SECONDS: how long a Docker call waits for a free pooled # connection before failing, for both pools. Keep in step with the @WithDefault on # EmulatorConfig.DockerConfig.connectionRequestTimeoutSeconds: a value set here WINS over the annotation. diff --git a/src/test/java/io/floci/aws/config/ApplicationDefaultsTest.java b/src/test/java/io/floci/aws/config/ApplicationDefaultsTest.java index 5ce70fee80..0d31782209 100644 --- a/src/test/java/io/floci/aws/config/ApplicationDefaultsTest.java +++ b/src/test/java/io/floci/aws/config/ApplicationDefaultsTest.java @@ -16,6 +16,10 @@ import static org.junit.jupiter.api.Assertions.assertTrue; class ApplicationDefaultsTest { + private static JsonNode productionConfig() throws IOException { + return new YAMLMapper().readTree(Path.of("src/main/resources/application.yml").toFile()); + } + @Test void productionConfigEnablesCloudTrailByDefault() throws IOException { try (InputStream configStream = getClass().getClassLoader().getResourceAsStream("application.yml")) { @@ -33,7 +37,7 @@ class ApplicationDefaultsTest { @Test void productionConfigUsesExpectedRequestSizeLimit() throws IOException { - JsonNode config = new YAMLMapper().readTree(Path.of("src/main/resources/application.yml").toFile()); + JsonNode config = productionConfig(); assertEquals(2048, config.path("floci").path("protocols").path("max-request-size").asInt(), @@ -42,7 +46,7 @@ class ApplicationDefaultsTest { @Test void productionConfigUsesTheAwsSqsMaximumMessageSize() throws IOException, NoSuchMethodException { - JsonNode config = new YAMLMapper().readTree(Path.of("src/main/resources/application.yml").toFile()); + JsonNode config = productionConfig(); assertEquals(1048576, config.path("floci").path("services").path("sqs").path("max-message-size").asInt(), @@ -58,7 +62,7 @@ class ApplicationDefaultsTest { @Test void productionConfigListensOnLoopbackWithoutNetworkExposureConsent() throws IOException, NoSuchMethodException { - JsonNode config = new YAMLMapper().readTree(Path.of("src/main/resources/application.yml").toFile()); + JsonNode config = productionConfig(); assertEquals("127.0.0.1", config.path("quarkus").path("http").path("host").asText(), "production application.yml should listen on loopback by default"); @@ -74,7 +78,7 @@ class ApplicationDefaultsTest { @Test void productionConfigDoesNotSeedIamDeployerPrincipalByDefault() throws IOException { - JsonNode config = new YAMLMapper().readTree(Path.of("src/main/resources/application.yml").toFile()); + JsonNode config = productionConfig(); assertFalse(config.path("floci") .path("services") @@ -86,7 +90,7 @@ class ApplicationDefaultsTest { @Test void productionConfigRejectsPrivateJwtTargetsByDefault() throws Exception { - JsonNode config = new YAMLMapper().readTree(Path.of("src/main/resources/application.yml").toFile()); + JsonNode config = productionConfig(); assertFalse(config.path("floci") .path("security") @@ -111,19 +115,11 @@ class ApplicationDefaultsTest { "a stock Floci should refuse a PostgreSQL IAM token generated for another endpoint, as RDS does"); } + // Catches: a max-connections in application.yml that silently disagrees with the @WithDefault fallback. @Test - void productionConfigSizesTheDockerPoolForTheLambdaRuntimeApiPortRange() throws IOException, NoSuchMethodException { - JsonNode floci = new YAMLMapper().readTree(Path.of("src/main/resources/application.yml").toFile()) - .path("floci"); - int maxConnections = floci.path("docker").path("max-connections").asInt(); - JsonNode lambda = floci.path("services").path("lambda"); - int runtimeApiPorts = lambda.path("runtime-api-max-port").asInt() - - lambda.path("runtime-api-base-port").asInt() + 1; - - assertTrue(maxConnections >= 2 * runtimeApiPorts, - "each live Lambda container holds two Docker connections (log follow and exit watcher), so " - + "max-connections " + maxConnections + " should cover the " + runtimeApiPorts - + " containers the runtime API port range allows"); + void productionConfigDeclaresTheDockerPoolAtItsDefault() throws IOException, NoSuchMethodException { + int maxConnections = productionConfig() + .path("floci").path("docker").path("max-connections").asInt(); WithDefault fallback = EmulatorConfig.DockerConfig.class .getMethod("maxConnections") @@ -133,23 +129,40 @@ class ApplicationDefaultsTest { "the @WithDefault must match application.yml, which wins over it"); } + // Catches: a streaming pool too small for the Lambda containers the runtime API port range allows, + // so log streams, exit watchers and extensions fail to get a connection well before that limit. + @Test + void productionConfigSizesTheStreamingDockerPoolForTheLambdaRuntimeApiPortRange() throws IOException { + JsonNode floci = productionConfig() + .path("floci"); + int streamingMaxConnections = floci.path("docker").path("streaming-max-connections").asInt(); + JsonNode lambda = floci.path("services").path("lambda"); + int runtimeApiPorts = lambda.path("runtime-api-max-port").asInt() + - lambda.path("runtime-api-base-port").asInt() + 1; + + assertTrue(streamingMaxConnections >= 4 * runtimeApiPorts, + "each live Lambda container holds a streaming connection for its log follow, its exit watcher " + + "and each extension, so streaming-max-connections " + streamingMaxConnections + + " should cover the " + runtimeApiPorts + + " containers the runtime API port range allows with two extensions each"); + } + // Catches: streaming-max-connections declared and documented but absent from the shipped // application.yml, or a yml value that silently disagrees with the @WithDefault fallback. @Test void productionConfigDeclaresTheStreamingDockerPoolAtItsDefault() throws IOException, NoSuchMethodException { - JsonNode streamingMaxConnections = new YAMLMapper() - .readTree(Path.of("src/main/resources/application.yml").toFile()) + JsonNode streamingMaxConnections = productionConfig() .path("floci").path("docker").path("streaming-max-connections"); assertFalse(streamingMaxConnections.isMissingNode(), "streaming-max-connections should be declared in application.yml"); - assertEquals(512, streamingMaxConnections.asInt()); + assertEquals(2048, streamingMaxConnections.asInt()); WithDefault fallback = EmulatorConfig.DockerConfig.class .getMethod("streamingMaxConnections") .getAnnotation(WithDefault.class); assertNotNull(fallback, "streamingMaxConnections should declare a fallback default"); - assertEquals("512", fallback.value(), + assertEquals("2048", fallback.value(), "the @WithDefault must match application.yml, which wins over it"); } @@ -157,8 +170,7 @@ class ApplicationDefaultsTest { // value that silently disagrees with the @WithDefault fallback. @Test void productionConfigDeclaresTheDockerLeaseTimeoutAtItsDefault() throws IOException, NoSuchMethodException { - JsonNode leaseTimeout = new YAMLMapper() - .readTree(Path.of("src/main/resources/application.yml").toFile()) + JsonNode leaseTimeout = productionConfig() .path("floci").path("docker").path("connection-request-timeout-seconds"); assertFalse(leaseTimeout.isMissingNode(), @@ -177,8 +189,7 @@ class ApplicationDefaultsTest { // silently disagrees with the @WithDefault fallback. @Test void productionConfigDeclaresTheDockerApiTimeoutAtItsDefault() throws IOException, NoSuchMethodException { - JsonNode apiTimeout = new YAMLMapper() - .readTree(Path.of("src/main/resources/application.yml").toFile()) + JsonNode apiTimeout = productionConfig() .path("floci").path("docker").path("api-timeout-seconds"); assertFalse(apiTimeout.isMissingNode(), "api-timeout-seconds should be declared in application.yml"); diff --git a/src/test/java/io/floci/aws/core/common/docker/RetryingDockerHttpClientTest.java b/src/test/java/io/floci/aws/core/common/docker/RetryingDockerHttpClientTest.java index e032dd9fda..e6d8ee6556 100644 --- a/src/test/java/io/floci/aws/core/common/docker/RetryingDockerHttpClientTest.java +++ b/src/test/java/io/floci/aws/core/common/docker/RetryingDockerHttpClientTest.java @@ -337,6 +337,48 @@ class RetryingDockerHttpClientTest { } } + // Catches: a container wait on the streaming transport losing the replay the control-plane + // transport gives it, so each stale socket spends one of the Lambda exit watcher's few re-arms. + @Test + void containerWaitRetrierReplaysAWaitThroughRepeatedBrokenPipes() { + Response ok = mock(Response.class); + FakeTransport delegate = new FakeTransport(attempt -> { + if (attempt < 3) { + throw brokenPipe(); + } + return ok; + }); + RetryingDockerHttpClient client = RetryingDockerHttpClient.forContainerWaits(delegate, MAX_ATTEMPTS, 0L); + Request wait = Request.builder() + .method(Request.Method.POST) + .path("/containers/abc/wait?condition=not-running") + .build(); + + assertSame(ok, client.execute(wait)); + assertEquals(3, delegate.calls.get()); + } + + // Catches: the wait-only decorator replaying anything else the streaming transport sends: an exec + // start would re-run its command, and log or attach streams are never replayed there. + @Test + void containerWaitRetrierReplaysNothingElse() { + for (Request request : List.of( + Request.builder().method(Request.Method.POST).path("/exec/abc/start") + .bodyBytes("{}".getBytes(StandardCharsets.UTF_8)).build(), + Request.builder().method(Request.Method.GET).path("/containers/abc/logs?follow=1").build(), + Request.builder().method(Request.Method.POST).path("/containers/abc/attach?stream=1").build(), + Request.builder().method(Request.Method.GET).path("/_ping").build())) { + FakeTransport delegate = new FakeTransport(attempt -> { + throw brokenPipe(); + }); + RetryingDockerHttpClient client = + RetryingDockerHttpClient.forContainerWaits(delegate, MAX_ATTEMPTS, 0L); + + assertThrows(RuntimeException.class, () -> client.execute(request), request.path()); + assertEquals(1, delegate.calls.get(), request.path()); + } + } + @Test void retriesOnlyANamedVolumeCreate() { // Catches: replaying an unnamed volume create, which makes a second volume and orphans the @@ -512,17 +554,26 @@ class RetryingDockerHttpClientTest { } } + // Catches: the control-plane transport losing its retries, the streaming transport losing the + // container-wait replay, or the streaming transport replaying a log stream. @Test - void producerWrapsControlPlaneTransportOnly() { + void producerWrapsEachTransportInItsOwnReplayPolicy() { DockerHttpClient raw = new FakeTransport(attempt -> null); - DockerHttpClient controlPlane = DockerClientProducer.wrapForRole(raw, "control-plane"); - DockerHttpClient streaming = DockerClientProducer.wrapForRole(raw, "streaming"); assertSame(RetryingDockerHttpClient.class, controlPlane.getClass(), "the control-plane transport must be wrapped in the retry decorator"); assertNotSame(raw, controlPlane); - assertSame(raw, streaming, - "the streaming transport (log-follow, exec output) must stay unwrapped"); + + FakeTransport failing = new FakeTransport(attempt -> { + throw brokenPipe(); + }); + DockerHttpClient streaming = DockerClientProducer.wrapForRole(failing, "streaming"); + Request logs = Request.builder().method(Request.Method.GET).path("/containers/abc/logs?follow=1").build(); + + assertInstanceOf(RetryingDockerHttpClient.class, streaming, + "the streaming transport must replay container waits"); + assertThrows(RuntimeException.class, () -> streaming.execute(logs)); + assertEquals(1, failing.calls.get(), "the streaming transport must never replay a log stream"); } } diff --git a/src/test/java/io/floci/aws/services/lambda/LambdaImageConfigTest.java b/src/test/java/io/floci/aws/services/lambda/LambdaImageConfigTest.java index dbdf3965bd..e31a99b911 100644 --- a/src/test/java/io/floci/aws/services/lambda/LambdaImageConfigTest.java +++ b/src/test/java/io/floci/aws/services/lambda/LambdaImageConfigTest.java @@ -253,7 +253,8 @@ class LambdaImageConfigTest { ContainerReachableEndpoint reachableEndpoint = new ContainerReachableEndpoint(config, dockerHostResolver, embeddedDnsServer, null, 4566); LaunchedContainerAwsEnv awsEnv = new LaunchedContainerAwsEnv(reachableEndpoint); - launcher = new ContainerLauncher(containerBuilder, lifecycleManager, logStreamer, imageResolver, + launcher = new ContainerLauncher(containerBuilder, lifecycleManager, mock(DockerClient.class), + logStreamer, imageResolver, runtimeApiServerFactory, dockerHostResolver, config, ecrRegistryManager, mock(LambdaLayerService.class), awsEnv, mock(LambdaExecutionRoleCredentials.class), null); diff --git a/src/test/java/io/floci/aws/services/lambda/launcher/ContainerLauncherCodeVolumeReuseTest.java b/src/test/java/io/floci/aws/services/lambda/launcher/ContainerLauncherCodeVolumeReuseTest.java index 2ca32b0c8e..cdd2a71fca 100644 --- a/src/test/java/io/floci/aws/services/lambda/launcher/ContainerLauncherCodeVolumeReuseTest.java +++ b/src/test/java/io/floci/aws/services/lambda/launcher/ContainerLauncherCodeVolumeReuseTest.java @@ -64,7 +64,8 @@ class ContainerLauncherCodeVolumeReuseTest { RuntimeException populateFailure; RecordingLauncher(ContainerLifecycleManager lifecycleManager, EmulatorConfig config) { - super(mock(ContainerBuilder.class), lifecycleManager, mock(ContainerLogStreamer.class), + super(mock(ContainerBuilder.class), lifecycleManager, mock(DockerClient.class), + mock(ContainerLogStreamer.class), mock(ImageResolver.class), mock(RuntimeApiServerFactory.class), mock(DockerHostResolver.class), config, mock(EcrRegistryManager.class), mock(LambdaLayerService.class), mock(LaunchedContainerAwsEnv.class), @@ -280,7 +281,7 @@ class ContainerLauncherCodeVolumeReuseTest { when(containerBuilder.newContainer("img")).thenReturn(builder); when(builder.build()).thenThrow(new IllegalStateException("stop before Docker")); ContainerLauncher real = new ContainerLauncher(containerBuilder, lifecycleManager, - mock(ContainerLogStreamer.class), mock(ImageResolver.class), + mock(DockerClient.class), mock(ContainerLogStreamer.class), mock(ImageResolver.class), mock(RuntimeApiServerFactory.class), mock(DockerHostResolver.class), config, mock(EcrRegistryManager.class), mock(LambdaLayerService.class), mock(LaunchedContainerAwsEnv.class), mock(LambdaExecutionRoleCredentials.class), null); diff --git a/src/test/java/io/floci/aws/services/lambda/launcher/ContainerLauncherCopyRetryTest.java b/src/test/java/io/floci/aws/services/lambda/launcher/ContainerLauncherCopyRetryTest.java index 6b0141a88e..3fe1c0b29f 100644 --- a/src/test/java/io/floci/aws/services/lambda/launcher/ContainerLauncherCopyRetryTest.java +++ b/src/test/java/io/floci/aws/services/lambda/launcher/ContainerLauncherCopyRetryTest.java @@ -33,7 +33,7 @@ class ContainerLauncherCopyRetryTest { // no longer builds; the copy paths under test read nothing else from it. EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS); when(config.services().lambda().codeVolumePopulateConcurrency()).thenReturn(Optional.empty()); - return new ContainerLauncher(null, null, null, null, null, null, config, null, null, null, null, null); + return new ContainerLauncher(null, null, null, null, null, null, null, config, null, null, null, null, null); } @Test diff --git a/src/test/java/io/floci/aws/services/lambda/launcher/ContainerLauncherTest.java b/src/test/java/io/floci/aws/services/lambda/launcher/ContainerLauncherTest.java index ac87dca305..1b5879d9c8 100644 --- a/src/test/java/io/floci/aws/services/lambda/launcher/ContainerLauncherTest.java +++ b/src/test/java/io/floci/aws/services/lambda/launcher/ContainerLauncherTest.java @@ -10,6 +10,7 @@ import com.github.dockerjava.api.command.ExecStartCmd; import com.github.dockerjava.api.command.InspectContainerCmd; import com.github.dockerjava.api.command.InspectContainerResponse; import com.github.dockerjava.api.command.ListContainersCmd; +import com.github.dockerjava.api.command.WaitContainerCmd; import com.github.dockerjava.api.exception.NotFoundException; import com.github.dockerjava.api.model.AccessMode; import com.github.dockerjava.api.model.ContainerConfig; @@ -109,6 +110,7 @@ class ContainerLauncherTest { @Mock EmbeddedDnsServer embeddedDnsServer; @Mock RuntimeApiServer runtimeApiServer; @Mock DockerClient dockerClient; + @Mock DockerClient streamingDockerClient; @Mock LambdaExecutionRoleCredentials executionRoleCredentials; @Mock LambdaLayerService layerService; @Mock Ec2Service ec2Service; @@ -256,7 +258,7 @@ class ContainerLauncherTest { new ContainerReachableEndpoint(config, dockerHostResolver, embeddedDnsServer, null, 4566); ContainerLauncher backgroundLauncher = new ContainerLauncher( new ContainerBuilder(config, dockerHostResolver, embeddedDnsServer), - lifecycleManager, logStreamer, imageResolver, runtimeApiServerFactory, + lifecycleManager, streamingDockerClient, logStreamer, imageResolver, runtimeApiServerFactory, dockerHostResolver, config, ecrRegistryManager, layers, new LaunchedContainerAwsEnv(endpoint), executionRoleCredentials, ec2Service); LambdaFunction fn = new LambdaFunction(); @@ -509,7 +511,7 @@ class ContainerLauncherTest { networkResolver, new ContainerEngineDetector(dockerClient)); ContainerReachableEndpoint endpoint = new ContainerReachableEndpoint(config, dockerHostResolver, embeddedDnsServer, null, 4566); - return new ContainerLauncher(builder, lifecycleManager, logStreamer, selectedResolver, + return new ContainerLauncher(builder, lifecycleManager, streamingDockerClient, logStreamer, selectedResolver, runtimeApiServerFactory, dockerHostResolver, config, ecrRegistryManager, layerService, new LaunchedContainerAwsEnv(endpoint), executionRoleCredentials, ec2Service); @@ -2448,7 +2450,7 @@ class ContainerLauncherTest { launchCmds.add(launchCmd); return launchCmd; }); - lenient().when(dockerClient.execStartCmd(argThat(id -> id != null && id.startsWith("exec-launch-")))) + lenient().when(streamingDockerClient.execStartCmd(launchedExecId())) .thenAnswer(invocation -> { ExecStartCmd start = mock(ExecStartCmd.class); when(start.exec(any())).thenAnswer(startInvocation -> { @@ -2463,11 +2465,16 @@ class ContainerLauncherTest { return launchCmds; } + /** Matches the id of an exec {@link #stubExtensionDiscoveryFromTar} created for an extension launch. */ + private static String launchedExecId() { + return argThat(id -> id != null && id.startsWith("exec-launch-")); + } + /** Overrides the default exec-start stub so the callback the launcher supplies is driven with a * real STDOUT {@link Frame} carrying {@code output}, exercising the frame-to-CloudWatch path * rather than only completing the callback. */ private void stubExecStartEmittingFrame(String output) { - lenient().when(dockerClient.execStartCmd(argThat(id -> id != null && id.startsWith("exec-launch-")))) + lenient().when(streamingDockerClient.execStartCmd(launchedExecId())) .thenAnswer(invocation -> { ExecStartCmd start = mock(ExecStartCmd.class); when(start.exec(any())).thenAnswer(startInvocation -> { @@ -2517,6 +2524,28 @@ class ContainerLauncherTest { inOrder.verify(dockerClient, atLeastOnce()).execCreateCmd("container-123"); } + // Catches: the extension exec or the exit watch running on the control-plane client, where + // each warm container would hold a lease for its whole lifetime and starve short Docker calls. + @Test + void launchFunction_holdsExtensionAndExitStreamsOnTheStreamingClient() throws Exception { + stubExtensionDiscovery("lambda-adapter"); + WaitContainerCmd wait = mock(WaitContainerCmd.class); + when(streamingDockerClient.waitContainerCmd("container-123")).thenReturn(wait); + when(wait.exec(any())).thenAnswer(invocation -> invocation.getArgument(0)); + + LambdaFunction fn = new LambdaFunction(); + fn.setFunctionName("streaming-pool-fn"); + fn.setPackageType("Image"); + fn.setImageUri("123456789012.dkr.ecr.us-east-1.amazonaws.com/repo:latest"); + + launcher.launch(fn); + + verify(streamingDockerClient).execStartCmd(launchedExecId()); + verify(streamingDockerClient).waitContainerCmd("container-123"); + verify(dockerClient, never()).execStartCmd(anyString()); + verify(dockerClient, never()).waitContainerCmd(anyString()); + } + /** * Extension stdout/stderr must reach the function's CloudWatch log group. `docker logs` — and * therefore ContainerLogStreamer.attach(), which uses logContainerCmd — only covers the @@ -2534,7 +2563,8 @@ class ContainerLauncherTest { ContainerLauncher launcherWithRealStreamer = new ContainerLauncher( new ContainerBuilder(config, dockerHostResolver, embeddedDnsServer), lifecycleManager, - new ContainerLogStreamer(dockerClient, cloudWatchLogs), + streamingDockerClient, + new ContainerLogStreamer(streamingDockerClient, cloudWatchLogs), imageResolver, runtimeApiServerFactory, dockerHostResolver, config, ecrRegistryManager, mock(LambdaLayerService.class), diff --git a/src/test/java/io/floci/aws/services/lambda/launcher/LambdaExitWatcherTest.java b/src/test/java/io/floci/aws/services/lambda/launcher/LambdaExitWatcherTest.java index 56358a923c..2fb0fb4d55 100644 --- a/src/test/java/io/floci/aws/services/lambda/launcher/LambdaExitWatcherTest.java +++ b/src/test/java/io/floci/aws/services/lambda/launcher/LambdaExitWatcherTest.java @@ -30,13 +30,15 @@ class LambdaExitWatcherTest { private final List delays = new ArrayList<>(); private long now; private DockerClient docker; + private DockerClient streamingDocker; private InspectContainerCmd inspect; @BeforeEach void setUp() { docker = mock(DockerClient.class); + streamingDocker = mock(DockerClient.class); WaitContainerCmd wait = mock(WaitContainerCmd.class); - when(docker.waitContainerCmd(CONTAINER)).thenReturn(wait); + when(streamingDocker.waitContainerCmd(CONTAINER)).thenReturn(wait); when(wait.exec(any())).thenAnswer(invocation -> { WaitContainerResultCallback callback = invocation.getArgument(0); armed.add(callback); @@ -48,7 +50,7 @@ class LambdaExitWatcherTest { /** A watch whose clock is {@link #now} and whose scheduler records each delay and runs the task at once. */ private void watch() { - new LambdaExitWatcher(docker, CONTAINER, exits::add, (delay, task) -> { + new LambdaExitWatcher(docker, streamingDocker, CONTAINER, exits::add, (delay, task) -> { delays.add(delay); task.run(); }, () -> now).arm();