[Repo Assist] fix: use TcpListener(0) and StartAsync in XmlExtensions tests to avoid Windows CI failures#1774
Merged
dsyme merged 2 commits intoMay 8, 2026
Conversation
…d Windows CI failures On Windows CI, Hyper-V and Docker reserve ranges of ports that are not visible via GetActiveTcpListeners(). The previous random-port approach could pick a port in one of these excluded ranges, causing Kestrel to fail with SocketException (10013: WSAEACCES) when binding. Replace with the same TcpListener(0) approach already used in Http.fs: ask the OS to bind port 0, read the assigned port (guaranteed not excluded), then release the listener before Kestrel binds it. Also switch from RunAsync (fire-and-forget) to StartAsync, which returns only after the server is listening. This removes the need for Thread.Sleep(100) in every test and makes server readiness deterministic. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
🤖 This is an automated pull request from Repo Assist, an AI assistant for this repository.
Root Cause
On Windows CI,
XmlExtensions.fstests were intermittently failing with:This error (WSAEACCES) occurs when Kestrel tries to bind a port that is in a Windows excluded port range — ranges reserved by Hyper-V, Docker, or Windows services. These excluded ports are not visible via
IPGlobalProperties.GetActiveTcpListeners(), so the previous random-port approach would pick such a port, consider it "free", and then fail at the Kestrel bind step.Fix
Two changes to
startXmlHttpLocalServer()intests/FSharp.Data.Core.Tests/XmlExtensions.fs:1.
TcpListener(0)port selection (likeHttp.fsalready does)Before (flawed random approach):
After (OS-assigned port, never excluded):
Asking the OS to bind port
0lets the kernel pick a port from the dynamic range, guaranteeing it is not in any excluded range.2.
StartAsync()instead ofRunAsync()+Thread.Sleep(100)Before:
app.RunAsync(baseAddress)is fire-and-forget; each test then calledThread.Sleep(100)hoping the server started.After:
app.StartAsync()returns only after the server is listening, making readiness deterministic and removing 13Thread.Sleep(100)calls.Evidence
The failure was observed in workflow run 25557443533 on the
build-windowsjob.Http.fsalready usedTcpListener(0)and was not affected.Test Status