Skip to content

fix: route durable function container traffic over a dedicated network - #9400

Merged
seshubaws merged 9 commits into
developfrom
fix/durable-local-networking
Nov 10, 2026
Merged

seshubaws merged 9 commits into
developfrom
fix/durable-local-networking

Conversation

@seshubaws

@seshubaws seshubaws commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

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 are created on the network with a unique name, the emulator invokes them by that name, and they reach the emulator by container name. They join at creation time because Finch only resolves containers that were on the network when they were created. --container-host-interface is respected again.
  • A running emulator container whose configuration does not match is replaced instead of reused.
  • An external emulator keeps reaching the containers through the host. --docker-network host does not put containers in host network mode, so they join the emulator's network like any other.

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

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@seshubaws
seshubaws requested a review from a team as a code owner November 3, 2026 23:54
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.
@seshubaws
seshubaws force-pushed the fix/durable-local-networking branch from 49abbdd to b87f76c Compare November 4, 2026 00:01

@aws-sam-tooling-bot aws-sam-tooling-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Results

Reviewed: 2fd518e..b87f76c
Files: 4
Comments: 1

@seshubaws

seshubaws commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

@aws-sam-tooling-bot

aws-sam-tooling-bot Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

🧪 Hands-on test: No problems observed in 7 scenarios

Commit b7d1a3a · build LambdaToolingHandsOn-Docker:194b1e60-34b6-46ef-bd82-cb290b45fe20. The plan's scenarios ran on an isolated build host; a problem is reported only if it reproduced at least twice. Passing scenarios show only that these checks behaved as expected, not that the change is correct.

Scenarios

Scenario Planned check Result Runner's note
S1 Main path: a sam local invoke of a durable function completes when the emulator and Lambda container talk over the sam-… ✅ pass Head: samdev local invoke HelloWorld exited 0 with 'Hello, World!' and an execution ARN. docker network inspect sam-durable-execution printed driver=bridge, and no sam-durable-* containers remained. …
S2 start-lambda with --warm-containers EAGER (8 durable functions set up in parallel) and --container-host-interface 127.0… ✅ pass Head (run twice): start-lambda with EAGER warm containers and --container-host-interface 127.0.0.1 was ready after 7 polls. There was 1 emulator on 127.0.0.1:9014->9014/tcp on network sam-durable-exe…
S3 A running emulator container on the old configuration (port published on all interfaces, not on sam-durable-execution) … ✅ pass A stale emulator was started at 0.0.0.0:9014->9014/tcp on the bridge network. Head: invoke exited 0, logged 'Replacing durable functions emulator container started with an outdated configuration', re…
S4 Confirms or refutes the dismissed finding lt-f87372258f53: with --docker-network host, the durable container and the em… ✅ pass Head: invoke with --docker-network host exited 0 with 'Hello, World!' and no connection, polling or start errors. This refutes static finding lt-f87372258f53. The base comparison was not run because …
S5 An existing setup with a user-supplied --docker-network keeps working. The container is now created on sam-durable-exec… ✅ pass Head: invoke with --docker-network sam-hands-on-net (a user network) exited 0 with 'Hello, World!', no 'Container creation failed' and no traceback, and left no sam-durable-* containers. The base com…
S6 Two concurrent invokes in separate directories, each with its own emulator name and port, while the sam-durable-executi… ✅ pass The network was removed first (empty listing). Two concurrent head invokes with emulators sam-durable-emu-a:9101 and sam-durable-emu-b:9102 both exited 0 with 'Hello, World!'. There was no network-cr…
S7 External emulator path: with DURABLE_EXECUTIONS_EXTERNAL_EMULATOR_PORT set, the Lambda container skips the network and … ⏭️ skipped Not run. The planned external emulator must run with 'docker run --network host' so it can reach the Lambda container at localhost:, and the tester's guardrails forbid host-network containers (…
S8 The PR's updated unit tests pass against the PR code. ✅ pass Head: the 4 planned unit test files passed (246 passed in 20.70s, exit 0).
Runner's notes in full
  • S1: Head: samdev local invoke HelloWorld exited 0 with 'Hello, World!' and an execution ARN. docker network inspect sam-durable-execution printed driver=bridge, and no sam-durable-* containers remained. Base: invoke also exited 0 with 'Hello, World!', and the network did not exist ('network sam-durable-execution not found'). The console script is samdev because setup uses SAM_CLI_DEV=1.
  • S2: Head (run twice): start-lambda with EAGER warm containers and --container-host-interface 127.0.0.1 was ready after 7 polls. There was 1 emulator on 127.0.0.1:9014->9014/tcp on network sam-durable-execution, plus 8 containers named sam-durable-function-<12 hex>, each on sam-durable-execution with 127.0.0.1:->8080/tcp. The HelloWorld invoke returned HTTP 200 with X-Amz-Durable-Execution-Arn and 'Hello, World!'. No tracebacks. Base: EAGER startup failed with '409 ... container name /sam-durable-execution-emulator is already in use' (the race the PR fixes), and its containers were bound to 0.0.0.0 with Docker-generated names. After SIGINT, head left 7 of 8 warm Lambda containers running. Base LAZY start-lambda also left 1 of 2 warm durable containers after SIGINT, so this leak predates the PR and is not reported as a finding. A first SIGINT attempt was ignored because bash background jobs ignore SIGINT (harness issue); later runs used a launcher that restores SIGINT.
  • S3: A stale emulator was started at 0.0.0.0:9014->9014/tcp on the bridge network. Head: invoke exited 0, logged 'Replacing durable functions emulator container started with an outdated configuration', returned 'Hello, World!', and left no sam-durable-* containers. Its one 'Reusing existing running emulator container' line comes 14 s later, when the Lambda container attaches to the new emulator. Base: logged 'Reusing existing running emulator container' for the stale container and also succeeded.
  • S4: Head: invoke with --docker-network host exited 0 with 'Hello, World!' and no connection, polling or start errors. This refutes static finding lt-f87372258f53. The base comparison was not run because of time.
  • S5: Head: invoke with --docker-network sam-hands-on-net (a user network) exited 0 with 'Hello, World!', no 'Container creation failed' and no traceback, and left no sam-durable-* containers. The base comparison was not run because of time.
  • S6: The network was removed first (empty listing). Two concurrent head invokes with emulators sam-durable-emu-a:9101 and sam-durable-emu-b:9102 both exited 0 with 'Hello, World!'. There was no network-create error and no traceback, exactly 1 sam-durable-execution network existed afterwards, and no containers were left. In the first attempt, invoker B exited 126 with 'timeout: failed to run command samdev: Permission denied' before SAM started (launcher issue). The rerun with the full binary path passed.
  • S7: Not run. The planned external emulator must run with 'docker run --network host' so it can reach the Lambda container at localhost:, and the tester's guardrails forbid host-network containers (the tool rejected the command). A bridge-network emulator cannot reach localhost ports on the host, so the scenario has no equivalent test.

🤖 Automated hands-on test — not a review approval · model claude-opus-5.5 · Kiro kiro-cli 2.33.1 · build LambdaToolingHandsOn-Docker:194b1e60-34b6-46ef-bd82-cb290b45fe20 · commit b7d1a3a

History (9)
Commit Result When (UTC) Build
b7d1a3a No problems observed 2026-11-07 07:05 LambdaToolingHandsOn-Docker:194b1e60-34b6-46ef-bd82-cb290b45fe20
b4c18e2 Superseded 2026-11-07 06:55 LambdaToolingHandsOn-Docker:a3431aa1-cf8b-4434-ae6f-f8536e643e40
d380254 Superseded 2026-11-07 06:47 LambdaToolingHandsOn-Docker:a3072c53-7c9f-41db-935b-ddee40ffb545
bd54fc0 No problems observed 2026-11-05 01:40 LambdaToolingHandsOn-Docker:18aa8ab5-bba6-4c0a-a50c-f8cbd4ae24b8
2b2f74a Problems reproduced: start-lambda --warm-containers EAGER still fails intermittently with 409 confli… 2026-11-05 01:13 LambdaToolingHandsOn-Docker:50b6ea9f-3b6a-4c35-9be6-2f10fee508b7
f88bf98 Partial 2026-11-05 00:31 LambdaToolingHandsOn-Docker:4ca01e85-2604-441d-8969-201644338114
ed7658d Problems reproduced: Durable executions fail with --docker-network host: emulator cannot reach the f… 2026-11-04 20:06 LambdaToolingHandsOn-Docker:9c376367-b394-4600-8178-3cd3a5c46fc6
49abbdd Superseded 2026-11-04 00:17 LambdaToolingHandsOn-Docker:ef48be15-c9ce-4612-935e-7d3d3434546c
b87f76c Problems reproduced: With --docker-network host, durable invoke fails: emulator cannot connect to th… 2026-11-04 00:17 LambdaToolingHandsOn-Docker:9f3ff377-385a-42b4-9e11-6494f7d008c4

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.

@aws-sam-tooling-bot aws-sam-tooling-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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.

@aws-sam-tooling-bot aws-sam-tooling-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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.

@aws-sam-tooling-bot aws-sam-tooling-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 Hands-on test reproduced 1 new problem on commit 2b2f74a. Commands and evidence are in the hands-on comment.

  1. [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:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 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.
Vandita2020
Vandita2020 previously approved these changes Nov 5, 2026
@seshubaws
seshubaws requested a review from valerena November 5, 2026 22:07
valerena
valerena previously approved these changes Nov 6, 2026
@seshubaws

seshubaws commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor Author

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.
@seshubaws
seshubaws dismissed stale reviews from valerena and Vandita2020 via d380254 November 7, 2026 06:30
@seshubaws
seshubaws merged commit 06bd63d into develop Nov 10, 2026
56 of 106 checks passed
@seshubaws
seshubaws deleted the fix/durable-local-networking branch November 10, 2026 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants