The transport tests cope with Windows port exclusion ranges and slow listener binds #379

Merged
claude merged 4 commits from feature/375-windows-port-failures into develop 2026-11-12 06:42:48 -05:00
Owner

The transport tests no longer fail on Windows when a port the system hands out for one protocol is reserved for the other, or when a listener binds slowly. Test code only; no product change.

Causes, each reproduced on lofnheim

  • Windows hands out port-0 ports one after the other from a machine-wide counter per protocol, and keeps separate excluded ranges for UDP and TCP. A port-0 bind skips only its own protocol's ranges, so "bind one protocol on port 0, then the other on the same number" is refused for hundreds of consecutive numbers once the counter is inside the other protocol's block. The helpers gave up after 20 tries, and each failed call moved the counter by only 20: nine tests failed in one run (1450).
  • The same shape, TCP first and then UDP, failed PlainForwarderClientTests (run 1451) and StubZoneNsPullerTests with WSAEACCES.
  • DnsCryptListenerTests picked its port with a TCP-only helper and waited a fixed 200 ms for the listeners to bind. Under CPU load the first tests ran before the UDP socket was bound ("forcibly closed", "actively refused"; run 1454).

Fixes

  • LocalAddresses.GetFreePort (five identical copies) picks a random port in the dynamic range 49152-65535 (RFC 6335 §6) and binds TCP and UDP on it explicitly, so a refused pick costs one attempt; up to 2000 attempts.
  • The DNSCrypt tests start the UDP listener on port 0, start TCP on the port it got, and wait for the bind outcome (IsListening, or the listener task ending) instead of sleeping.
  • The forwarder's scripted upstream and the stub-zone test retry their TCP and UDP pair up to 2000 times and hold both sockets.

Verified

  • lofnheim, the suite as the job runs it, three times back to back: the first run fully green, the other two with one failure each, the SecondaryForwarder zone test of #374. The unfixed baseline failed on WSAEACCES.
  • The DNSCrypt project passed 5 of 5 under the CPU load that broke the old tests.
  • Linux, coder and verifier: DnsCrypt 54, Plain 21, DnsOverTls 48, DnsOverQuic 21, Server.Core 356, Forwarding 258, Authoritative 671, all green. The build has 0 warnings and csharpier is clean.
  • The verifier accepted the three commits. Its low findings are left for a follow-up: on a path where the test has already failed, the new start-up helper does not stop its listeners after a timeout, and the two pair helpers leak one listener on their last attempt.
  • GetFreePort is still reserve-and-release for the tests that need one number across protocols and addresses; its random picks overlap the Linux ephemeral range, a small window the verifier noted and did not measure.

Closes #375

🤖 Generated with Claude Code

https://claude.ai/code/session_01T33E3pmQvqkTriyQUMNUTK

The transport tests no longer fail on Windows when a port the system hands out for one protocol is reserved for the other, or when a listener binds slowly. Test code only; no product change. **Causes, each reproduced on lofnheim** - Windows hands out port-0 ports one after the other from a machine-wide counter per protocol, and keeps separate excluded ranges for UDP and TCP. A port-0 bind skips only its own protocol's ranges, so "bind one protocol on port 0, then the other on the same number" is refused for hundreds of consecutive numbers once the counter is inside the other protocol's block. The helpers gave up after 20 tries, and each failed call moved the counter by only 20: nine tests failed in one run (1450). - The same shape, TCP first and then UDP, failed `PlainForwarderClientTests` (run 1451) and `StubZoneNsPullerTests` with WSAEACCES. - `DnsCryptListenerTests` picked its port with a TCP-only helper and waited a fixed 200 ms for the listeners to bind. Under CPU load the first tests ran before the UDP socket was bound ("forcibly closed", "actively refused"; run 1454). **Fixes** - `LocalAddresses.GetFreePort` (five identical copies) picks a random port in the dynamic range 49152-65535 (RFC 6335 §6) and binds TCP and UDP on it explicitly, so a refused pick costs one attempt; up to 2000 attempts. - The DNSCrypt tests start the UDP listener on port 0, start TCP on the port it got, and wait for the bind outcome (`IsListening`, or the listener task ending) instead of sleeping. - The forwarder's scripted upstream and the stub-zone test retry their TCP and UDP pair up to 2000 times and hold both sockets. **Verified** - lofnheim, the suite as the job runs it, three times back to back: the first run fully green, the other two with one failure each, the SecondaryForwarder zone test of #374. The unfixed baseline failed on WSAEACCES. - The DNSCrypt project passed 5 of 5 under the CPU load that broke the old tests. - Linux, coder and verifier: DnsCrypt 54, Plain 21, DnsOverTls 48, DnsOverQuic 21, Server.Core 356, Forwarding 258, Authoritative 671, all green. The build has 0 warnings and csharpier is clean. - The verifier accepted the three commits. Its low findings are left for a follow-up: on a path where the test has already failed, the new start-up helper does not stop its listeners after a timeout, and the two pair helpers leak one listener on their last attempt. - `GetFreePort` is still reserve-and-release for the tests that need one number across protocols and addresses; its random picks overlap the Linux ephemeral range, a small window the verifier noted and did not measure. Closes #375 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01T33E3pmQvqkTriyQUMNUTK
Refs #375

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T33E3pmQvqkTriyQUMNUTK
Refs #375

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T33E3pmQvqkTriyQUMNUTK
The forwarder and stub-zone tests keep searching for a port both UDP and TCP accept instead of stopping after 20 tries
Some checks failed
Build / Build and Test Deb and RPM Packages (push) Successful in 40s
Build / Publish Release (push) Has been skipped
Build / Pipeline (push) Failing after 0s
Build / Pack and Push NuGet Packages (dns-core) (pull_request) Successful in -1m51s
Build / Test .NET (push) Successful in 6m10s
Build / Pack and Push NuGet Packages (dns-server) (pull_request) Successful in -1m56s
Build / Build Binary (linux-amd64) (pull_request) Successful in -45s
Build / Build Binary (linux-arm64) (pull_request) Successful in -32s
Build / Build Binary (macos-amd64) (pull_request) Successful in -42s
Build / Build Binary (macos-arm64) (pull_request) Successful in -43s
Build / Build Binary (windows-amd64) (pull_request) Successful in -25s
Build / Stage Draft Release (push) Successful in -2m33s
Build / Smoke Test the Windows Binary (pull_request) Failing after 11s
Build / Pack and Push NuGet Packages (common) (push) Successful in -1m44s
Build / Pack and Push NuGet Packages (dhcp) (push) Successful in -1m53s
Build / Pack and Push NuGet Packages (dns-core) (push) Successful in -1m53s
Build / Build Arch Linux Packages (pull_request) Successful in -2m2s
Build / Pack and Push NuGet Packages (dns-server) (push) Successful in -1m37s
Build / Build and Push Image (pull_request) Successful in -2m30s
Build / Build Binary (linux-amd64) (push) Successful in -56s
Build / Build and Test Deb and RPM Packages (pull_request) Successful in 7s
Build / Build Binary (linux-arm64) (push) Successful in -16s
Build / Build Binary (macos-amd64) (push) Successful in 1s
Build / Build Binary (macos-arm64) (push) Successful in -26s
Build / Build Binary (windows-amd64) (push) Successful in -42s
Build / Smoke Test the Windows Binary (push) Failing after 11s
Build / Publish Release (pull_request) Has been skipped
Build / Pipeline (pull_request) Failing after 0s
Build / Build Arch Linux Packages (push) Successful in -1m37s
Build / Build and Push Image (push) Successful in -2m30s
b70e72ebec
Closes #375

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T33E3pmQvqkTriyQUMNUTK
Merge remote-tracking branch 'origin/develop' into feature/375-windows-port-failures
Some checks failed
Build / Build Binary (linux-amd64) (push) Has been skipped
Build / Build Binary (windows-amd64) (push) Has been skipped
Build / Pack and Push NuGet Packages (dns-core) (push) Has been skipped
Build / Pack and Push NuGet Packages (dns-server) (push) Has been skipped
Build / Build Binary (linux-arm64) (push) Has been skipped
Build / Build Binary (macos-amd64) (push) Has been skipped
Build / Build Binary (macos-arm64) (push) Has been skipped
Build / Smoke Test the Windows Binary (push) Has been skipped
Build / Build and Test Deb and RPM Packages (push) Has been skipped
Build / Build Arch Linux Packages (push) Has been skipped
Build / Publish Release (push) Has been skipped
Build / Pipeline (push) Failing after 0s
Build / Test .NET (pull_request) Successful in 5m18s
Build / Build and Push Image (push) Has been skipped
Build / Stage Draft Release (pull_request) Successful in -2m34s
Build / Pack and Push NuGet Packages (common) (pull_request) Successful in -2m23s
Build / Pack and Push NuGet Packages (dns-core) (pull_request) Successful in -2m1s
Build / Pack and Push NuGet Packages (dhcp) (pull_request) Successful in -2m6s
Build / Pack and Push NuGet Packages (dns-server) (pull_request) Successful in -1m52s
Build / Build Binary (linux-arm64) (pull_request) Successful in -49s
Build / Build Binary (macos-arm64) (pull_request) Successful in -56s
Build / Build Binary (windows-amd64) (pull_request) Successful in -58s
Build / Build Binary (linux-amd64) (pull_request) Successful in -49s
Build / Build Binary (macos-amd64) (pull_request) Successful in -40s
Build / Build and Push Image (pull_request) Successful in -2m29s
Build / Build Arch Linux Packages (pull_request) Successful in -2m20s
Build / Smoke Test the Windows Binary (pull_request) Successful in 16s
Build / Publish Release (pull_request) Successful in -2m32s
Build / Pipeline (pull_request) Successful in 0s
Build / Build and Test Deb and RPM Packages (pull_request) Successful in -46s
51b39530df
claude merged commit 13cd4a1ef5 into develop 2026-11-12 06:42:48 -05:00
claude deleted branch feature/375-windows-port-failures 2026-11-12 06:42:49 -05:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
lantea-one/ninlil!379
No description provided.