perf(lambda): avoid code-copy helper shutdown delay (#5646)

* perf(lambda): avoid code-copy helper shutdown delay

* test(lambda): scope the code-copy fixture threshold

Signed-off-by: Andre Kurait <akurait@amazon.com>

* chore(ci): retry the EKS registry fixture check

Signed-off-by: Andre Kurait <akurait@amazon.com>

---------

Signed-off-by: Andre Kurait <akurait@amazon.com>
This commit is contained in:
Andre Kurait authored and GitHub committed 2026-10-15 06:57:38 -04:00
1 parent 5a72b4f561
commit f08a443ec9
3 files changed
+54 -2

No files matched your search

+4
View File
@@ -534,6 +534,10 @@ These AWS Lambda operations have no handler in Floci. Calls will return `404` or
Only first-time populates are gated. Warm containers, already-populated volumes, and
functions under 32 MB are never serialised by this.
The temporary copy helper is removed without a stop grace period once copying
finishes or fails. It runs no Lambda code; actual execution environments retain
their normal shutdown and extension-drain behavior.
!!! note "Bounding warm containers"
After an invocation the container stays warm so the next call skips the cold start, and is
reaped only after `container-idle-timeout-seconds` of inactivity. Each function keeps up to
@@ -989,7 +989,8 @@ public class ContainerLauncher implements LambdaRuntimeLauncher {
} finally {
if (helperId != null) {
try {
lifecycleManager.stopAndRemove(helperId, null);
// This helper only sleeps while the copy runs; it has no runtime to drain.
lifecycleManager.stopAndRemove(helperId, null, 0);
} catch (Exception e) {
LOG.warnv("Could not remove code-volume helper {0}: {1}", helperId, e.getMessage());
}
@@ -1017,6 +1017,7 @@ class ContainerLauncherTest {
fn.setHandler("index.handler");
fn.setCodeLocalPath(codePath.toString());
fn.setCodeSha256("large-fn-sha-v1");
when(lifecycleManager.create(any())).thenReturn("helper-123", "container-123");
long original = ContainerLauncher.CODE_VOLUME_MIN_BYTES;
try {
@@ -1042,13 +1043,49 @@ class ContainerLauncherTest {
// Two creates: the helper + the real container. The helper is discarded.
verify(lifecycleManager, times(2)).create(any());
verify(lifecycleManager, atLeastOnce()).ensureVolume(any());
verify(lifecycleManager, times(1)).stopAndRemove(any(), any()); // the helper only
verify(lifecycleManager).stopAndRemove("helper-123", null, 0);
verify(lifecycleManager, never()).stopAndRemove(any(), any());
InOrder order = inOrder(lifecycleManager);
order.verify(lifecycleManager).stopAndRemove("helper-123", null, 0);
order.verify(lifecycleManager).create(any());
order.verify(lifecycleManager).startCreated(eq("container-123"), any());
// A superseded code-version volume is never deleted synchronously within a single launch
// (see the cleanupSupersededVolumes tests below for the deferred sweep; this fn has no
// prior volume to supersede, since it's the fn's first deploy here).
verify(lifecycleManager, never()).removeVolume(any());
}
@Test
void launchFunction_failedCodeCopyImmediatelyRemovesOnlyItsHelper() throws Exception {
Path codePath = Files.createDirectory(tempDir.resolve("failed-code-copy"));
Files.write(codePath.resolve("bundle.bin"), new byte[8 * 1024]);
LambdaFunction fn = new LambdaFunction();
fn.setFunctionName("copy-failure");
fn.setRuntime("nodejs20.x");
fn.setHandler("index.handler");
fn.setCodeLocalPath(codePath.toString());
fn.setCodeSha256("copy-failure-sha");
when(lifecycleManager.create(any())).thenReturn("helper-123");
doThrow(new IllegalStateException("fixture copy failed"))
.when(dockerClient).copyArchiveToContainerCmd("helper-123");
withLoweredCodeVolumeThreshold(() -> {
RuntimeException failure = assertThrows(RuntimeException.class, () -> launcher.launch(fn));
assertTrue(failure.getMessage().contains("fixture copy failed"));
});
InOrder order = inOrder(lifecycleManager, dockerClient);
order.verify(lifecycleManager).startCreated(eq("helper-123"), any());
order.verify(dockerClient).copyArchiveToContainerCmd("helper-123");
order.verify(lifecycleManager).stopAndRemove("helper-123", null, 0);
verify(lifecycleManager, times(1)).create(any());
verify(lifecycleManager, never()).stopAndRemove(any(), any());
verify(lifecycleManager, never()).removeVolume(any());
verify(runtimeApiServerFactory).release(runtimeApiServer);
assertFalse(Files.exists(tempDir.resolve("lambda-codevol-markers")
.resolve(ContainerLauncher.codeVolumeName(fn))));
}
@Test
void launchFunction_releasesRuntimeApiServer_whenCodeVolumePopulateFails() throws Exception {
// Regression for the runtime-api port leak: the volume path allocates a runtime-api server
@@ -1915,4 +1952,14 @@ class ContainerLauncherTest {
assertEquals(List.of("/opt/extensions/lambda-adapter", "/opt/extensions/otel-collector"),
capturedLaunchPaths(launchCmds));
}
private static void withLoweredCodeVolumeThreshold(Runnable action) {
long original = ContainerLauncher.CODE_VOLUME_MIN_BYTES;
try {
ContainerLauncher.CODE_VOLUME_MIN_BYTES = 4 * 1024;
action.run();
} finally {
ContainerLauncher.CODE_VOLUME_MIN_BYTES = original;
}
}
}