Skip to content

fix(#1035): a warm container is invalidated when its code or configuration changes - #1080

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1035-lambda-warm-container-invalidation
Sep 18, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1035-lambda-warm-container-invalidation

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #1035.

LambdaExecutor pools a warm container by function ARN alone, and containerHandle records no code
identity at all — no CodeSha256, no RevisionId, no image URI — so nothing in the invoke path could
notice that a container is running code the function no longer has. Only a shutdown, a state reset and
the idle TTL ever dropped an entry, and the TTL measures idle time, so a function invoked in a loop
kept its stale container indefinitely: GetFunction reported the new digest while Invoke returned the
old code's output, and the response a caller was asserting on was the stale one.

DeleteFunction then CreateFunction under the same name is the same defect from the other direction,
since the ARN is derived from the name — the name-derived-key trap #903 fixed for event-source pollers,
on the live path. #903 fixed the reset half of this and its own ResetForRun comment states the rest
of the bug in prose. This is the live-path half, and it needs no reset.

UpdateFunctionConfiguration is in scope on evidence, not assumption

The issue listed five mutable members and left this as a question. Three are demonstrably fixed at
docker run time, on both the ZIP and the image path:

Member Where it is baked in
Runtime runtimeToImage(fn.Runtime) chooses the image
Handler passed as AWS_LAMBDA_FUNCTION_HANDLER and as the container's command argument
Environment one -e flag per variable

MemorySize and Timeout are the two that reach no container at all — no --memory flag and no
timeout is passed — so they are the members that would not need this. The eviction is unconditional
anyway: deciding per-member means comparing five members against a handle that stores none of them, and
a needless cold start is cheaper than a missed one serving the wrong answer.

PublishVersion and the alias operations are deliberately absent. The pool is keyed by the unqualified
ARN and the invoke path resolves a qualifier to the same function record, so neither changes what a
container should be running.

Shape

  • LambdaExecutor.Evict(functionARN) — per-ARN, not a drain. DrainPool (A state reset leaves Lambda ESM pollers and the Lambda/RDS container pools running #903) would stop the stale
    container and every other function's with it, for a change to one function's code. It stops the
    container outside the lock, following DrainPool, since docker stop blocks for as long as the
    container takes to exit. It drops the pool entry whether or not the stop succeeded, because
    leaving the entry would serve exactly the stale code the eviction exists to prevent.
  • LambdaPlugin.evictWarmContainer is called by the three handlers after a successful write, so a
    refused update disturbs nothing — a save that failed stored no new code, and the container is still
    running what the function has.
  • stopContainer now runs docker rm -f after the stop. It did not before, so every evicted
    container stayed on the host as an exited container for the life of the machine — the inverse of
    what A state reset leaves Lambda ESM pollers and the Lambda/RDS container pools running #903 taught RDSExecutor, and it matters more now that eviction is no longer only the idle TTL
    and shutdown.
  • deleteFunction releases lambdaZipStateKey. The bytes of every deleted function accumulated before;
    no stale read followed, since the invoke path is gated on ZipStored and a recreated function sets
    that for itself, so it was a leak rather than a wrong answer.

The issue's fourth criterion cannot be met, and that is a finding

It asks for a Docker-gated test that the invoke after UpdateFunctionCode runs the new code.
startZIPContainer writes the package to /var/task/function.zip and mounts the directory —
nothing extracts it — so the runtime interface finds one archive where it expects a module tree and
index.handler cannot be imported whatever the code is. There is no observable difference between the
old code and the new one to assert on, with or without Docker.

That is consistent with CLAUDE.md's scope boundary, which puts running a Lambda's code out of scope.
Whether the path should therefore be documented as inert or completed is filed as #1079 rather than
decided here. The invalidation is asserted on container identity instead, which is observable
everywhere.

Verification

Six tests in emulator/lambda_warm_container_test.go, all over HTTP against a served plugin with an
executor attached (the default test server has none), using a new WarmPoolARNsForTest accessor in the
manner of RDSActiveContainerCountForTest:

  • UpdateFunctionCode on one of two warm functions drops that one's entry and no other — the only
    shape that distinguishes per-ARN eviction from a drain;
  • UpdateFunctionConfiguration drops it, asserted on Timeout alone, which is the member that would be
    exempt under a per-member rule, so the assertion says something;
  • DeleteFunction drops the entry and releases the stored package;
  • a refused UpdateFunctionCode (404, absent function) evicts nothing, including a warm entry
    injected under that same absent name — the direction an eviction placed before the write gets wrong;
  • a tag write and a GetFunction keep the container, which is the honesty half: the eviction must not
    spread to the rest of the plugin;
  • a plugin with no executor at all — every run but a Docker one — survives all three operations.

The injected container IDs name no container, so docker stop inside an eviction fails and is logged.
No test skips on Docker's absence for that reason: the entry must go regardless, and asserting that is
stronger than asserting the stop.

Full gate green: gofmt/go build/go vet, golangci-lint run ./... (0 issues), go test -race ./...
on both toolchains, test/e2e, scripts/check-discarded-unmarshal.sh, scripts/check-doc-versions.sh,
gen-service-reference -check, gen-authz-reference -check, and the docs site build.

…ation changes

The Lambda executor's warm pool is keyed by function ARN alone and its handle
records no code identity, so nothing could notice a container running code the
function no longer has. UpdateFunctionCode, UpdateFunctionConfiguration and
DeleteFunction now evict that one function's entry after the write succeeds.

Closes #1035
@scttfrdmn scttfrdmn added this to the v0.119.0 milestone Sep 18, 2026
@scttfrdmn scttfrdmn added type: bug Something is not working correctly area: lambda labels Sep 18, 2026
@codecov

codecov Bot commented Sep 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.18919% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/lambda_exec.go 90.00% 2 Missing ⚠️
emulator/lambda_plugin.go 88.23% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 93c7e0e into main Sep 18, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1035-lambda-warm-container-invalidation branch September 18, 2026 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: lambda type: bug Something is not working correctly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lambda: a warm container is never invalidated, so UpdateFunctionCode then Invoke runs the previous code

1 participant