Fix HTTP test port race and self-request origin#3570
Open
ChihweiLHBird wants to merge 2 commits into
Open
Conversation
2b379f9 to
0c53025
Compare
Signed-off-by: Zhiwei Liang <zhiwei.liang@zliang.me>
Signed-off-by: Zhiwei Liang <zhiwei.liang@zliang.me>
0c53025 to
6b9e838
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 launchingspin 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 spurious404.Change
Production code
Test framework
--listen 127.0.0.1:0, then parse the actual bound port from this Spin process's startup output.Why the server change is needed
After the test harness switched to
127.0.0.1:0,HttpServer::listen_addrcould remain127.0.0.1:0even though the actual listener was bound to an assigned port. Self requests must use the real bound address, not the configured:0address. The server now storeslistener.local_addr()after binding and uses that address when configuringSelfRequestOrigin.For in-process tests,
InProcessSpinbuilds a server and driveshandle()directly without callingserve(), so no socket address is recorded. That path falls back to the configured listen address.