Repository navigation
fix: route durable function container traffic over a dedicated network - #9400
Conversation
Local durable executions now connect the emulator and the Lambda containers over a SAM CLI managed Docker network (sam-durable-execution) and address each other by name, instead of going through ports published on the host. - The emulator joins the network and its port is published on 127.0.0.1 only, since SAM CLI is the only thing that talks to it from the host. - Durable Lambda containers join the network under an alias, the emulator invokes them through it, and they reach the emulator by container name. --container-host-interface is respected again. - A running emulator container whose configuration does not match is replaced instead of reused. - An external emulator and containers on the host network keep reaching each other through the host.
49abbdd to
b87f76c
Compare
🧪 Hands-on test: No problems observed in 7 scenariosCommit Scenarios
Runner's notes in full
🤖 Automated hands-on test — not a review approval · model claude-opus-5.5 · Kiro kiro-cli 2.33.1 · build History (9)
|
The emulator could not reach durable function containers on Finch. They were attached to sam-durable-execution after creation with a network alias, and Finch only resolves the name and hostname of containers that join a network when they are created. Create the container directly on the emulator network instead, with a unique name and hostname that the emulator uses to invoke it.
There was a problem hiding this comment.
✅ Lambda Tooling PR Reviewer: No high-confidence issues found.
1 lower-confidence observation: these passed verification at a lower score, so check before acting
1. [ERROR_HANDLING] samcli/local/docker/durable_functions_emulator_container.py:130: Fallback after a failed network create hides the real Docker error
get_or_create_network assumes every docker.errors.APIError from networks.create means another SAM CLI process won the race, so it calls networks.get again. If the create failed for a different reason, such as Docker reporting that no non-overlapping address pool is available, that second lookup raises NotFound. The user then sees "network sam-durable-execution not found" instead of the real cause, and neither start() nor DurableLambdaContainer.create catches it. One fix is to catch NotFound from the retry lookup and re-raise the original create error.
SAM CLI does not run containers in host network mode for --docker-network host; it only skips joining a network, so the container stays on the default bridge. Treating it as on the host network pointed it at localhost for the emulator, which is the container itself, and had the emulator invoke it through host.docker.internal on a port published only on 127.0.0.1. Create these containers on the emulator network like any other.
There was a problem hiding this comment.
✅ Lambda Tooling PR Reviewer: No high-confidence issues found.
1 lower-confidence observation: these passed verification at a lower score, so check before acting
1. [ERROR_HANDLING] samcli/local/docker/durable_functions_emulator_container.py:130: get_or_create_network hides the real network creation error
Every docker.errors.APIError from networks.create is treated as a race with another SAM CLI process, and the code then calls networks.get again without a guard. If creation fails for a different reason, such as the daemon running out of address pools, the user gets a "network not found" error instead of the actual cause, and that error is not wrapped in a UserException. The image-pull path in this same file does wrap its errors. To check, make networks.create fail with a non-conflict error and see which exception reaches start().
get_or_create_network treated every failure to create the network as a race with another SAM CLI process and looked the network up again, so a real failure, such as the daemon running out of address pools, surfaced as an unwrapped "network not found" error. Report the create error as a UserException when the network still does not exist.
…rallel start-lambda --warm-containers EAGER creates every function's container in parallel. get_or_create_emulator_container checked and set its singleton without a lock, so several threads could each try to create the sam-durable-execution-emulator container and all but one failed with a 409 name conflict. Guard the singleton with a lock, and only share the emulator once it has started so that a failed start is retried by the next caller.
There was a problem hiding this comment.
🧪 Hands-on test reproduced 1 new problem on commit 2b2f74a. Commands and evidence are in the hands-on comment.
- [BUG] start-lambda --warm-containers EAGER still fails intermittently with 409 conflict on sam-durable-execution-emulator despite the new emulator lock · high · samcli/local/lambdafn/runtime.py:499
🤖 Automated hands-on test — not a review approval
| self._durable_execution_emulator_container.start_or_attach() | ||
| LOG.debug("Created and started durable functions emulator container") | ||
| return self._durable_execution_emulator_container | ||
| with self._emulator_lock: |
There was a problem hiding this comment.
🧪 Hands-on: [BUG] start-lambda --warm-containers EAGER still fails intermittently with 409 conflict on sam-durable-execution-emulator despite the new emulator lock (reproduced 2 times in S4). Commands and evidence: hands-on comment.
The emulator lock did not stop the 409 conflict on sam-durable-execution-emulator. The containers are initialized in parallel, and each task read the lazily created local_lambda_runner and lambda_runtime properties, which are not locked, so several threads could each create their own WarmLambdaRuntime. Each one had its own emulator lock and started its own emulator, and its warm containers were never cleaned up on shutdown. Create the runner and runtime once before starting the parallel tasks.
|
durable fns test on windows https://github.com/aws/aws-sam-cli/actions/runs/42309833090, 2 failures due to timeout, and tested on my mac machine (passed) So this PR has been verified on macOS Finch with native functions, Linux x86 Finch in CI, Linux Docker, and Windows WSL2 Docker. |
Finch on macOS returns an empty HostConfig for containers and reports the published ports only in NetworkSettings.Ports. The reuse check read only HostConfig.PortBindings, so it found no bindings and treated the running emulator as outdated. Every sam local callback or sam local execution command then stopped and replaced the emulator, which killed the execution in progress. Check the bindings in NetworkSettings.Ports as well.
Local durable executions now connect the emulator and the Lambda containers over a SAM CLI managed Docker network (sam-durable-execution) and address each other by name, instead of going through ports published on the host.
Which issue(s) does this change fix?
Why is this change necessary?
How does it address the issue?
What side effects does this change have?
Mandatory Checklist
PRs will only be reviewed after checklist is complete
make prpassesmake update-reproducible-reqsif dependencies were changedBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.