Skip to content

Fix HTTP test port race and self-request origin#3570

Open
ChihweiLHBird wants to merge 2 commits into
spinframework:mainfrom
ChihweiLHBird:flaky-integration-test-port-conflict-fix
Open

Fix HTTP test port race and self-request origin#3570
ChihweiLHBird wants to merge 2 commits into
spinframework:mainfrom
ChihweiLHBird:flaky-integration-test-port-conflict-fix

Conversation

@ChihweiLHBird

@ChihweiLHBird ChihweiLHBird commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes flaky HTTP integration test startup caused by a test harness port race.

The harness previously selected a port by binding localhost:0, reading the assigned port, dropping that listener, and later launching spin up --listen 127.0.0.1:{port}. In parallel test runs, another process could claim that port before this Spin instance bound it. The old readiness check only proved that something accepted TCP connections on the port, so a test could accidentally send requests to the wrong Spin app and see a spurious 404.

Change

Production code

  • Track the actual bound HTTP listener address and use it for self-request origin setup.

Test framework

  • Start Spin with --listen 127.0.0.1:0, then parse the actual bound port from this Spin process's startup output.
  • Report early Spin startup failures with stdout/stderr.

Why the server change is needed

After the test harness switched to 127.0.0.1:0, HttpServer::listen_addr could remain 127.0.0.1:0 even though the actual listener was bound to an assigned port. Self requests must use the real bound address, not the configured :0 address. The server now stores listener.local_addr() after binding and uses that address when configuring SelfRequestOrigin.

For in-process tests, InProcessSpin builds a server and drives handle() directly without calling serve(), so no socket address is recorded. That path falls back to the configured listen address.

@ChihweiLHBird ChihweiLHBird force-pushed the flaky-integration-test-port-conflict-fix branch from 2b379f9 to 0c53025 Compare June 13, 2026 08:23
@ChihweiLHBird ChihweiLHBird marked this pull request as draft June 13, 2026 19:04
Signed-off-by: Zhiwei Liang <zhiwei.liang@zliang.me>
Signed-off-by: Zhiwei Liang <zhiwei.liang@zliang.me>
@ChihweiLHBird ChihweiLHBird force-pushed the flaky-integration-test-port-conflict-fix branch from 0c53025 to 6b9e838 Compare June 13, 2026 21:03
@ChihweiLHBird ChihweiLHBird changed the title Fix flaky HTTP integration test startup Fix HTTP test port race and self-request origin Jun 13, 2026
@ChihweiLHBird ChihweiLHBird marked this pull request as ready for review June 13, 2026 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant