Skip to content

[localserver] LocalServer's port 7000 conflicts with APFS File Sharing #550

@sebsto

Description

@sebsto

Expected behavior

swift run triggers the local server on port 7000. Developers can test invocations with curl -d '{ "name" : "Seb", "age" : 50 }' http://127.0.0.1:7000/invoke

Actual behavior

On macOS, TCP port 7000 is the default for APFS file sharing. It seems listening even when File Sharing is disabled in System Preferences.

➜  ~ lsof -i :7000
COMMAND    PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
ControlCe 1100  sst    8u  IPv4 0xb0aff743814fe68b      0t0  TCP *:afs3-fileserver (LISTEN)
ControlCe 1100  sst    9u  IPv6 0xe86c5132b3d1f4d9      0t0  TCP *:afs3-fileserver (LISTEN)
Image

In this configuration, the LocalServer starts but fails to complete the payload processing. It crashes with LambdaRuntimeError.Code.invocationMissingMetadata

It looks like, after processing the payload, the runtime call /next again to receive the next payload to process and, this time, it's not the LocalServer that responds, but the APFS file server.

The runtime crashes because the expected HTTP headers are not present in the APFS file server response.

Full log here:

➜  HelloJSON git:(main) ✗ LAMBDA_USE_LOCAL_DEPS=../.. LOG_LEVEL=trace swift run
warning: 'hellojson': [INFO] Compiling against swift-aws-lambda-runtime located at ../..
Creating working copy for https://github.com/swift-server/swift-aws-lambda-runtime.git
Working copy of https://github.com/swift-server/swift-aws-lambda-runtime.git resolved at 2.0.0-beta.1
[1/1] Planning build
Building for debugging...
[24/24] Compiling AWSLambdaRuntime LambdaClock.swift
Build of product 'HelloJSON' complete! (0.95s)
2025-08-24T10:42:41+0200 debug LambdaRuntime: [AWSLambdaRuntime] LambdaRuntime initialized
2025-08-24T10:42:41+0200 info LambdaRuntime: host="127.0.0.1" port=7000 [AWSLambdaRuntime] Server started and listening
2025-08-24T10:42:41+0200 trace LambdaRuntime: lambda_ip=127.0.0.1 lambda_port=7000 [AWSLambdaRuntime] Connection to control plane created
2025-08-24T10:42:41+0200 trace LambdaRuntime: [AWSLambdaRuntime] Handling a new connection
2025-08-24T10:42:41+0200 trace LambdaRuntime: URI=GET /2018-06-01/runtime/invocation/next [AWSLambdaRuntime] Processing request
2025-08-24T10:42:41+0200 trace LambdaRuntime: URI=GET /2018-06-01/runtime/invocation/next [AWSLambdaRuntime] /next waiting for /invoke
2025-08-24T10:42:42+0200 trace LambdaRuntime: [AWSLambdaRuntime] Handling a new connection
2025-08-24T10:42:42+0200 trace LambdaRuntime: Body={"name": "seb", "age": 50} URI=POST /invoke [AWSLambdaRuntime] Processing request
2025-08-24T10:42:42+0200 trace LambdaRuntime: URI=POST /invoke requestId=19990901640875 [AWSLambdaRuntime] /invoke received invocation, pushing it to the pool and wait for a lambda response
2025-08-24T10:42:42+0200 trace LambdaRuntime: URI=GET /2018-06-01/runtime/invocation/next requestId=19990901640875 [AWSLambdaRuntime] /next retrieved invocation
2025-08-24T10:42:42+0200 trace LambdaRuntime: URI=GET /2018-06-01/runtime/invocation/next requestId=19990901640875 [AWSLambdaRuntime] Writing response for 202
2025-08-24T10:42:42+0200 trace LambdaRuntime: URI=GET /2018-06-01/runtime/invocation/next requestId=19990901640875 [AWSLambdaRuntime] Sending status and headers
2025-08-24T10:42:42+0200 trace LambdaRuntime: URI=GET /2018-06-01/runtime/invocation/next requestId=19990901640875 [AWSLambdaRuntime] Sending body
2025-08-24T10:42:42+0200 trace LambdaRuntime: URI=GET /2018-06-01/runtime/invocation/next requestId=19990901640875 [AWSLambdaRuntime] Sending end
2025-08-24T10:42:42+0200 trace LambdaRuntime: [AWSLambdaRuntime] Close lambda runtime client
2025-08-24T10:42:42+0200 trace LambdaRuntime: error=CancellationError() [AWSLambdaRuntime] The task was cancelled
2025-08-24T10:42:42+0200 trace LambdaRuntime: error=CancellationError() [AWSLambdaRuntime] The task was cancelled
2025-08-24T10:42:42+0200 trace LambdaRuntime: [AWSLambdaRuntime] Done handling the connection
2025-08-24T10:42:42+0200 trace LambdaRuntime: [AWSLambdaRuntime] Done handling the connection
2025-08-24T10:42:42+0200 info LambdaRuntime: [AWSLambdaRuntime] Server shutting down
2025-08-24T10:42:42+0200 error LambdaRuntime: [AWSLambdaRuntime] Error during server shutdown: LambdaRuntimeError(code: AWSLambdaRuntime.LambdaRuntimeError.Code.invocationMissingMetadata, underlying: Optional(AWSLambdaRuntime.LambdaRuntimeError(code: AWSLambdaRuntime.LambdaRuntimeError.Code.nextInvocationMissingHeaderDeadline, underlying: nil)))
Swift/ErrorType.swift:254: Fatal error: Error raised at top level: AWSLambdaRuntime.LambdaRuntimeError(code: AWSLambdaRuntime.LambdaRuntimeError.Code.invocationMissingMetadata, underlying: Optional(AWSLambdaRuntime.LambdaRuntimeError(code: AWSLambdaRuntime.LambdaRuntimeError.Code.nextInvocationMissingHeaderDeadline, underlying: nil)))

Steps to reproduce

  1. clone the repo
  2. LOG_LEVEL=trace swift run
  3. From another terminal,

If possible, minimal yet complete reproducer code (or URL to code)

No response

What version of this project (swift-aws-lambda-runtime) are you using?

2.0.0-beta.1

Swift version

➜  ~ swift --version
Apple Swift version 6.1 (swift-6.1-RELEASE)
Target: arm64-apple-macosx15.0

Amazon Linux 2 docker image version

n/a

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions