Repository navigation
fix(#1035): a warm container is invalidated when its code or configuration changes - #1080
Merged
Merged
Conversation
…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
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1035.
LambdaExecutorpools a warm container by function ARN alone, andcontainerHandlerecords no codeidentity at all — no
CodeSha256, noRevisionId, no image URI — so nothing in the invoke path couldnotice 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:
GetFunctionreported the new digest whileInvokereturned theold code's output, and the response a caller was asserting on was the stale one.
DeleteFunctionthenCreateFunctionunder 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
ResetForRuncomment states the restof the bug in prose. This is the live-path half, and it needs no reset.
UpdateFunctionConfigurationis in scope on evidence, not assumptionThe issue listed five mutable members and left this as a question. Three are demonstrably fixed at
docker runtime, on both the ZIP and the image path:RuntimeruntimeToImage(fn.Runtime)chooses the imageHandlerAWS_LAMBDA_FUNCTION_HANDLERand as the container's command argumentEnvironment-eflag per variableMemorySizeandTimeoutare the two that reach no container at all — no--memoryflag and notimeout 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.
PublishVersionand the alias operations are deliberately absent. The pool is keyed by the unqualifiedARN 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 stalecontainer and every other function's with it, for a change to one function's code. It stops the
container outside the lock, following
DrainPool, sincedocker stopblocks for as long as thecontainer 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.evictWarmContaineris called by the three handlers after a successful write, so arefused update disturbs nothing — a save that failed stored no new code, and the container is still
running what the function has.
stopContainernow runsdocker rm -fafter thestop. It did not before, so every evictedcontainer 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 TTLand shutdown.
deleteFunctionreleaseslambdaZipStateKey. The bytes of every deleted function accumulated before;no stale read followed, since the invoke path is gated on
ZipStoredand a recreated function setsthat 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
UpdateFunctionCoderuns the new code.startZIPContainerwrites the package to/var/task/function.zipand mounts the directory —nothing extracts it — so the runtime interface finds one archive where it expects a module tree and
index.handlercannot be imported whatever the code is. There is no observable difference between theold 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 anexecutor attached (the default test server has none), using a new
WarmPoolARNsForTestaccessor in themanner of
RDSActiveContainerCountForTest:UpdateFunctionCodeon one of two warm functions drops that one's entry and no other — the onlyshape that distinguishes per-ARN eviction from a drain;
UpdateFunctionConfigurationdrops it, asserted onTimeoutalone, which is the member that would beexempt under a per-member rule, so the assertion says something;
DeleteFunctiondrops the entry and releases the stored package;UpdateFunctionCode(404, absent function) evicts nothing, including a warm entryinjected under that same absent name — the direction an eviction placed before the write gets wrong;
GetFunctionkeep the container, which is the honesty half: the eviction must notspread to the rest of the plugin;
The injected container IDs name no container, so
docker stopinside 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.