The plain-DNS listener tests do not fail on Windows when the OS refuses a port for a moment #341

Closed
opened 2026-11-06 11:25:18 -05:00 by claude · 0 comments
Owner
  • Draft: none (found while verifying #12)
  • Priority: low
  • Agent: coder
  • Depends on: none
  • Decisions: none

Why

  • On Lofnheim, Ninlil.Dns.Protocol.Plain.Tests fails in about 10% of runs: 5 of 50 runs, after 847bddeb.
  • In a failing run several tests fail together within 7 to 22 ms:
    • PlainListenAddressTests.NoListenAddresses_WhenThePortIsTaken... fails with a SocketException "access permissions" on a UDP bind to port 0 (PlainListenAddressTests.cs:67).
    • Others fail with InvalidOperationException "Could not find a port free for both UDP and TCP" from Fakes/LocalAddresses.cs:46 (GetFreePort, 20 attempts), for example UdpReceiveTests.StopAsync_... and DualStackClientAddressTests.UdpClientOverIPv4_....
  • This looks like short bursts in which Windows refuses ports to the process. netsh int ipv4 show excludedportrange protocol=udp lists 7 excluded ranges inside 49152-65535. The product code is not involved.
  • #18 runs the suite on the Windows runner, so this has to be reliable first.

What changes

  • Confirm the cause on Lofnheim: the excluded ranges (tcp and udp), and whether the failures cluster in time.
  • Make the reserve-and-release helpers in the Plain.Tests fakes (and any copy of the same helper in other test projects) retry a SocketException with a short backoff and a bounded total time, with a comment that says why.
  • Where a listener can expose its bound port, use port 0 and read the port back (AGENTS.md). TcpDnsListener cannot, so it keeps the bounded retry.

Acceptance

  • 50 Windows runs of Plain.Tests with no failures. Plain.Tests passes on Linux.
- **Draft:** none (found while verifying #12) - **Priority:** low - **Agent:** coder - **Depends on:** none - **Decisions:** none ### Why - On Lofnheim, `Ninlil.Dns.Protocol.Plain.Tests` fails in about 10% of runs: 5 of 50 runs, after `847bddeb`. - In a failing run several tests fail together within 7 to 22 ms: - `PlainListenAddressTests.NoListenAddresses_WhenThePortIsTaken...` fails with a `SocketException` "access permissions" on a UDP bind to port 0 (`PlainListenAddressTests.cs:67`). - Others fail with `InvalidOperationException` "Could not find a port free for both UDP and TCP" from `Fakes/LocalAddresses.cs:46` (`GetFreePort`, 20 attempts), for example `UdpReceiveTests.StopAsync_...` and `DualStackClientAddressTests.UdpClientOverIPv4_...`. - This looks like short bursts in which Windows refuses ports to the process. `netsh int ipv4 show excludedportrange protocol=udp` lists 7 excluded ranges inside 49152-65535. The product code is not involved. - #18 runs the suite on the Windows runner, so this has to be reliable first. ### What changes - Confirm the cause on Lofnheim: the excluded ranges (tcp and udp), and whether the failures cluster in time. - Make the reserve-and-release helpers in the Plain.Tests fakes (and any copy of the same helper in other test projects) retry a `SocketException` with a short backoff and a bounded total time, with a comment that says why. - Where a listener can expose its bound port, use port 0 and read the port back (AGENTS.md). `TcpDnsListener` cannot, so it keeps the bounded retry. ### Acceptance - [ ] 50 Windows runs of Plain.Tests with no failures. Plain.Tests passes on Linux.
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
lantea-one/ninlil#341
No description provided.