mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(lambda): give published versions their code location (#2012)
* test(lambda): cover invoking a published version LambdaVersionIntegrationTest covered publish, list and delete against a function with no code at all, so nothing ever invoked a version. Adds that case, plus a $LATEST baseline on a separate function so a failure is attributable to versioning rather than to the harness. Currently fails, reproducing #1987: the version invoke returns HTTP 200 with X-Amz-Function-Error: Unhandled and no result body, after the container logs Runtime.ImportModuleError ("Cannot find module 'index'") and the invoke times out at the 5s function timeout. The baseline is a separate function on purpose. Invoking $LATEST on the function under test leaves a warm container that the version-qualified invoke then reuses -- the warm pool is keyed by function name alone (#1988) -- so the version runs $LATEST's code and the assertion passes while the version path is still broken. An earlier draft of this test did exactly that and reported #1987 as fixed. * fix(lambda): give published versions their code publishVersion built the version snapshot by copying fields one at a time and copied no code location at all -- not just codeLocalPath but s3Bucket, s3Key, imageUri and codeSha256. A numeric qualifier resolves straight to that snapshot, so a version-qualified invoke launched a container for a function with no code. It timed out rather than failing because ContainerLauncher.launch only validated the code path when it was non-null, making the one state that always means "no code" the one state never checked. The container came up empty, the runtime logged Runtime.ImportModuleError where nobody saw it, and the caller waited out the whole function timeout before getting a 200 with X-Amz-Function-Error: Unhandled and no result body. Copy the fields that determine what runs -- code location for every package type, plus layers, architectures and ephemeral storage -- and make a missing code location an error for non-hot-reload Zip functions. The guard is what keeps the next dropped field from surfacing as a timeout somewhere else instead of an error at its cause. LambdaImageConfigTest.zipFunctionStillUsesHandlerAsCmd built a bare Zip function with no code path as a fixture shortcut; it now gets a @TempDir. The test covers cmd construction, not code validation. Closes #1987 * fix(lambda): copy remaining config fields and fix @Order collision Two follow-ups from review after the code-location fix: - publishVersion now also copies tracingMode, deadLetterTargetArn and kmsKeyArn onto the version snapshot. These are surfaced by every config-serializing endpoint the same as the code-location fields, and were dropped by the same hand-enumerated field copy. Verified through ListVersionsByFunction rather than GetFunction/ GetFunctionConfiguration with a :1 qualifier: those two resolve through LambdaService.getFunction(region, functionName), which hardcodes "$LATEST" in its storage lookup and never reads the qualifier, so they can't distinguish a version's stored config from $LATEST's — a separate, pre-existing gap, not fixed here. - LambdaVersionIntegrationTest had two methods at @Order(6) after merging main, which independently added a test at the same value. Renumbered to keep execution order deterministic; both tests use independent function fixtures so this was never a functional bug. Verified against a revert of each change: both new/moved assertions fail without their fix and pass with it restored. --------- Co-authored-by: Priamo <pgermosen@gmail.com>
This commit is contained in:
1 parent
7a2dc53b96
commit
42022fe937
4 files changed
+206
-9
No files matched your search
@@ -979,6 +979,27 @@ public class LambdaService {
|
||||
snapshot.setLastModified(System.currentTimeMillis());
|
||||
snapshot.setRevisionId(UUID.randomUUID().toString());
|
||||
|
||||
// Everything that determines what actually runs. Without these the snapshot describes a
|
||||
// function with no code: a version-qualified invoke resolves to it, launches a container
|
||||
// with nothing in it, and hangs to the function timeout instead of failing (#1987). A
|
||||
// published version is an immutable snapshot of code plus configuration, so it carries the
|
||||
// code location for every package type, not only Zip.
|
||||
snapshot.setCodeLocalPath(fn.getCodeLocalPath());
|
||||
snapshot.setCodeSha256(fn.getCodeSha256());
|
||||
snapshot.setS3Bucket(fn.getS3Bucket());
|
||||
snapshot.setS3Key(fn.getS3Key());
|
||||
snapshot.setHotReloadHostPath(fn.getHotReloadHostPath());
|
||||
snapshot.setImageUri(fn.getImageUri());
|
||||
snapshot.setImageConfigCommand(fn.getImageConfigCommand());
|
||||
snapshot.setImageConfigEntryPoint(fn.getImageConfigEntryPoint());
|
||||
snapshot.setImageConfigWorkingDirectory(fn.getImageConfigWorkingDirectory());
|
||||
snapshot.setLayers(fn.getLayers());
|
||||
snapshot.setArchitectures(fn.getArchitectures());
|
||||
snapshot.setEphemeralStorageSize(fn.getEphemeralStorageSize());
|
||||
snapshot.setTracingMode(fn.getTracingMode());
|
||||
snapshot.setDeadLetterTargetArn(fn.getDeadLetterTargetArn());
|
||||
snapshot.setKmsKeyArn(fn.getKmsKeyArn());
|
||||
|
||||
functionStore.save(region, snapshot);
|
||||
LOG.infov("Published version {0} for function {1}", version, functionName);
|
||||
return snapshot;
|
||||
|
||||
+18
-8
@@ -156,14 +156,24 @@ public class ContainerLauncher {
|
||||
|
||||
// For Zip functions, verify code exists before allocating any resources.
|
||||
// Hot-reload functions use a bind-mount; the Docker daemon validates the path at start.
|
||||
if (!fn.isHotReload()) {
|
||||
if (fn.getCodeLocalPath() != null) {
|
||||
Path codePath = Path.of(fn.getCodeLocalPath());
|
||||
if (!Files.exists(codePath)) {
|
||||
throw new RuntimeException("Code directory not found for function '"
|
||||
+ fn.getFunctionName() + "': " + fn.getCodeLocalPath()
|
||||
+ " (function may have been deleted or updated)");
|
||||
}
|
||||
// Image functions carry an imageUri rather than a local path.
|
||||
if (!fn.isHotReload() && !"Image".equals(fn.getPackageType())) {
|
||||
if (fn.getCodeLocalPath() == null) {
|
||||
// A null path used to skip validation entirely, which made the one state that
|
||||
// always means "no code" the one state never checked: the container started
|
||||
// empty, the runtime logged an ImportModuleError nobody saw, and the caller
|
||||
// waited out the whole function timeout. Failing here surfaces a dropped code
|
||||
// field at its cause instead of as a timeout somewhere else (#1987).
|
||||
throw new RuntimeException("No code location for function '"
|
||||
+ fn.getFunctionName() + "'"
|
||||
+ ("$LATEST".equals(fn.getVersion()) ? "" : " version " + fn.getVersion())
|
||||
+ " (function has no deployed code)");
|
||||
}
|
||||
Path codePath = Path.of(fn.getCodeLocalPath());
|
||||
if (!Files.exists(codePath)) {
|
||||
throw new RuntimeException("Code directory not found for function '"
|
||||
+ fn.getFunctionName() + "': " + fn.getCodeLocalPath()
|
||||
+ " (function may have been deleted or updated)");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user