Files
floci/src/main/java
David e4c690351f fix(lambda): replace the extracted package instead of merging into it (#2672)
* fix(lambda): replace the extracted package instead of merging into it

ZipExtractor wrote entries into the function's code directory without
clearing it first, so each deploy was layered on top of the last. Nothing
on the path resets the directory: CodeStore.delete runs only when a
function is deleted, codeStore.exists() is never called, and every deploy
of a function resolves to the same code path. Extraction was a merge where
the domain requires a replace, so a file removed between two deploys
survived and stayed loadable -- a handler pointing at a deleted module kept
resolving and running stale code. Real AWS replaces the package wholesale.

Extract into a sibling staging directory and swap it in once the whole
archive has been read: on success the old tree is deleted and staging is
moved into place, on failure staging is discarded and the previous
deployment is left untouched. That also makes extraction all-or-nothing.

Safe because the code directory is not bind-mounted into Lambda
containers -- ContainerLauncher tar-copies it into /var/task at launch, and
the only bind for task code is the hot-reload path, which uses a different
directory that never goes through extractTo.

Closes #2647

* fix(lambda): keep the previous package until the new one is installed

The install deleted the live tree and then moved the new one into place, so
a failure in the move left the function with no code at all and nothing to
restore: a failed update destroyed a working deployment.

Rename the old tree aside instead, move the new one in, and delete the old
only once the new one has landed. Every failure path now ends with one
complete package on disk. The interval in which the target is absent is two
renames within a directory rather than a recursive delete followed by a
move; it is narrowed, not closed, because POSIX cannot atomically exchange
two directories, and the javadoc records that limit rather than implying
atomicity.

install() is package private so the failure path can be driven directly. It
is unreachable through extractTo, because a rename between siblings does not
fail under any condition a test can arrange there.

* fix(lambda): do not fail a deployment that already installed

Two failure paths in install() reported the wrong outcome.

Deleting the superseded package threw out of install(), so a filesystem
error at that point failed the deployment even though the new tree was
already in place and serving. The caller then skipped its metadata and warm
pool updates for code that was live. That deletion is now best effort: it
logs and leaves the tree behind, because leaving a directory costs disk and
is recoverable, while misreporting the outcome is not.

Restoring the previous package after a failed move was itself unguarded. If
the restore also threw, its exception replaced the original failure and the
working package was left under a generated name nothing would look for. The
restore is now guarded, the original failure stays the exception thrown, the
restore failure is attached to it, and the stranded path is logged so it can
be moved back by hand.

The cleanup path has a regression test. The restore path does not: reaching
it needs the install rename to fail while the restore rename also fails, and
both are renames in one directory, so either both succeed or the first
rename fails before install is reached.
2026-08-28 18:51:43 -04:00
..