Skip to content

Fix race condition in the ListenWithoutBindIsTracked test case - #41352

Draft
Blue (OneBlue) wants to merge 9 commits into
masterfrom
user/oneblue/fix-tests-14
Draft

Blue (OneBlue) wants to merge 9 commits into
masterfrom
user/oneblue/fix-tests-14

Conversation

@OneBlue

Copy link
Copy Markdown
Collaborator

Summary of the Pull Request

This change solves a race condition in the tests: We're waiting for GNS to perform a port binding, but we're also calling bind() on the same port on the host. If the GNS bind comes right while we hold the bound socket, it will fail and the test will fail.

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

Copilot AI lite review requested due to automatic review settings August 13, 2026 19:40
@OneBlue
Blue (OneBlue) requested a review from a team as a code owner August 13, 2026 19:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the VerifyListenWithoutBindIsTracked test logic in the WSL Windows network test suite to eliminate a race between host-side bind() retries and the guest-side implicit port binding/tracking, making the test less flaky while still validating that the listen-without-bind scenario becomes reachable from the host.

Changes:

  • Keep the guest-side listening socket alive across multiple host connection attempts by accepting connections in a loop.
  • Replace the host-side “retry bind until it gets blocked” probe with a “retry connect until it succeeds” probe to avoid competing for the same port.
  • Explicitly target loopback (INADDR_LOOPBACK) for the host connection probe.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI review requested due to automatic review settings August 13, 2026 23:07
@OneBlue
Blue (OneBlue) marked this pull request as draft August 13, 2026 23:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings August 14, 2026 16:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings August 14, 2026 19:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings September 10, 2026 19:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new code introduces concrete correctness issues (Winsock error retrieval and varargs format/type mismatches) that should be fixed to avoid undefined behavior and misleading failures in tests.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (1)

test/windows/NetworkTests.cpp:2290

  • LogInfo uses printf-style formatting; assignedPort and ntohs(...) should be cast to unsigned int to match %u and avoid varargs type-mismatch UB.
                        LogInfo(
                            "connect() to port %u failed with %d; local source port is %u",
                            assignedPort,
                            connectError,
                            ntohs(localAddr.sin_port));
  • Files reviewed: 1/1 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment on lines 2268 to 2270
wil::unique_socket sock(socket(AF_INET, SOCK_STREAM, IPPROTO_TCP));
THROW_LAST_ERROR_IF(!sock);

Comment thread test/windows/NetworkTests.cpp Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 11, 2026 19:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

A critical formatting issue remains unresolved.

Get a fresh assessment by requesting another Copilot review.

Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread test/windows/NetworkTests.cpp Outdated
Copilot AI review requested due to automatic review settings September 11, 2026 19:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Two moderate findings remain unresolved.

Review details

Suppressed comments (2)

test/windows/NetworkTests.cpp:2311

  • Both %u arguments in this new diagnostic call receive values that undergo integral promotion to int (uint16_t and ntohs(...)), while %u requires unsigned int. This is undefined behavior and can produce misleading retry diagnostics; cast both arguments explicitly, matching the cast in the preceding LogInfo call.
                            "connect() to port %u failed with %d; local source port is %u",
                            assignedPort,
                            connectError,
                            ntohs(localAddr.sin_port));

test/windows/NetworkTests.cpp:2292

  • connect() succeeding only proves that some listener accepted 127.0.0.1:assignedPort; it does not prove the connection reached this guest. An unrelated host listener on the randomly selected port, or the localhost relay accepting before its guest-side connection is established, can make this retry pass even when the GNS mapping is missing or broken. Have the guest send a unique marker after accept() and require the host to receive it (with a timeout) before treating the attempt as successful.
                if (connect(sock.get(), reinterpret_cast<SOCKADDR*>(&addr), sizeof(addr)) == SOCKET_ERROR)
  • Files reviewed: 1/1 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings September 11, 2026 22:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The retry can succeed against an unrelated Windows service without confirming the guest listener accepted the connection.

Review details

Suppressed comments (1)

test/windows/NetworkTests.cpp:2292

  • A successful connect here does not prove that the connection reached the guest listener: if another Windows service happens to own this ephemeral port, the retry will pass even though GNS never installed the mapping. This test should send a sentinel and have the Perl listener acknowledge it (or otherwise verify data/acceptance in the guest) before treating the retry as success.
                if (connect(sock.get(), reinterpret_cast<SOCKADDR*>(&addr), sizeof(addr)) == SOCKET_ERROR)
  • Files reviewed: 1/1 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

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.

2 participants