You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bind devtools HTTP listeners without a probe-then-bind race - #1309
The devtools HTTP servers chose their port by probing for it: bind a TcpListener to 127.0.0.1:0, read the port, release it. They bound HttpListener to that port later, so another process could take it in between. When several selftest hosts run on one machine, the Devtools_* fixtures fail intermittently with HttpListenerException (32). This PR binds with bind-and-retry instead, in one helper shared by DevtoolsMcpServer and PreviewCaptureServer. mur devtools needs a different fix because a child process binds its port after a build, so it gets an exit-code handshake.
Why the old code raced (measured on Windows, .NET 10)
HttpListener.Start fails with 32 (ERROR_SHARING_VIOLATION) when any other socket owns the port: a listening socket on 127.0.0.1 or 0.0.0.0, or the local end of a live connection. It fails with 183 (ERROR_ALREADY_EXISTS) when another HttpListener, in any process, registered the same prefix.
Because of that, the probe socket can't stay open across Start. PreviewCaptureServer's TASK-026 placeholder had to be released before Start, so it narrowed the window without closing it. The threat model's claim that it was held until HttpListener bound was not accurate.
A failed Start disposes the HttpListener, so each retry needs a new instance. TIME_WAIT does not block HTTP.sys, and bind(0) never returns a port HTTP.sys holds.
What changes
LoopbackHttpListener (new, src/Reactor.Devtools) starts an HttpListener. If the bind fails with 32 or 183, an unpinned start probes another port and binds a new listener, up to 16 attempts. A pinned port gets exactly one attempt and fails with LoopbackPortUnavailableException.
DevtoolsMcpServer and PreviewCaptureServer now create and bind the listener in Start(). They set Port to the bound port before the accept loop starts, since IsAllowedHost compares the Host header against it. That also happens before the endpoint is announced in the banners, the devtools-ready line, the lockfile, and CAPTURE_PORT. The TASK-026 placeholder is removed.
Lifecycle: one System.Threading.Lock now covers the whole HTTP Start (bind, publish, announce) and all of Dispose. A repeated Start() is still a no-op, as HttpListener.Start was. A concurrent Start() waits for the first one's result. Once Dispose() returns, nothing is bound or announced. Dispose closes the listener with Close() alone, because HttpListener.Dispose already runs Stop() and then CleanupV2Config().
mur devtools: the supervisor probes a port and passes it to a child. The child binds it only after dotnet run builds, and again after each reload rebuild. Spec 024 requires the port to stay unbound during the rebuild, so the supervisor can't hold it.
The child now exits with 43 when its --mcp-port is held by another process.
The supervisor then picks a new port, but only if it picked the old one itself. That retry is bounded and printed.
A port the user pinned with --mcp-port is never moved; the supervisor reports it clearly instead.
The respawn loop moved into a Supervise method with injected delegates, so it can be unit-tested.
Docs: spec 024 documents the supervisor's handling of 43. The threat model's TASK-026 row (§7.1) is corrected, and §7.2 gains a port-TOCTOU entry. There is a CHANGELOG.md entry under [Unreleased] / Fixed, and the agent-facing devtools skill (skills/devtools.md and the plugin copy) describes the 43 path.
Linked issue / spec
Found during the devtools bug hunt; it was noted as a triage item in #1305. No issue was filed. This touches docs/specs/024-ai-agent-devtools.md (supervisor contract) and docs/security/threat-model.md (§7.1, §7.2).
Raw pattern under natural concurrency: 8 processes each ran the old probe-then-bind sequence 1,500 times. 2 of 12,000 binds failed, one with 32 and one with 183.
Real symptom: 15 rounds of 6 concurrent Reactor.AppTests.Host --self-test --filter Devtools_ runs, with background port churn. 1 of 90 host runs failed with not ok 24 Devtools_WaitForTimeoutLoggedAsErr_CRASH - HttpListenerException: The process cannot access the file because it is being used by another process. Alone, the same filter passes.
New regression tests (unit tier, headless; 29 tests)
LoopbackHttpListenerTests (9): the port is held by another socket (32) or another HttpListener (183), so the helper moves and serves a real request. A pinned port throws without being probed again. The helper gives up after MaxAttempts. configure runs on every attempt, including the one that binds. The 32/183 error-code mapping.
DevtoolsServerPortRaceTests (11): each server receives a probed port that another socket already holds, then serves on a new port. GET /mcp and GET /status return 200, which shows that Port was updated before the Host-header check ran. A pinned MCP port is never moved, and the host maps that failure to exit code 43. Start after Dispose throws. A second Start is a no-op, and Dispose frees the port. A probe seam parks the first Start mid-retry; a concurrent Start or Dispose then stays pending until the bind completes.
SupervisorLoopTests (9): a port the supervisor picked is re-picked and the child relaunched. A user-pinned port fails without moving. The supervisor gives up after 5 consecutive conflicts. A reload keeps the port and resets the conflict count. A failed build returns 2. Other exit codes propagate. The exit codes match the child's constants.
These tests fail when the fix is removed
I reverted the fix itself (no retry, supervisor ignores 43, host maps nothing) but kept the test seams. 12 of the original 23 new tests fail: 6 on the retry, 4 on the supervisor, 2 on the host mapping. The other 11 check pinned ports, propagation, and constant parity, which should hold with or without the fix.
I restored main's DevtoolsMcpServer and added only the probe seam. McpServer_ProbedPortTakenBeforeStart_ServesOnAFreshPort then fails with System.Net.HttpListenerException : The process cannot access the file because it is being used by another process. That is the production symptom.
Without the double-start guard, both *_SecondStart_* tests fail (the port moved from 52455 to 52456).
With the earlier flag-based lifecycle (bind outside the lock), all 4 concurrency tests fail with "returned while Start was still binding".
Gates
dotnet test tests/Reactor.Tests (Debug, x64), final code: 14,393 tests, 0 failed (64 skipped, all pre-existing), in the last 2 runs. Across about 20 full runs during the review rounds, two runs each had one failure. One was ReactorTraceRegressionTests.DisabledKeyword_skips_ReactorEventSource_WriteEvent_payload_marshal ("leaked 61776 B ... cap: 10000"). That is an existing race between tests: the test checks once that the Errors keyword is off, then counts its own thread's allocations over 10,000 calls. Meanwhile Docking/LayoutSerializerTests enables every ReactorEventSource keyword from another test thread, and if the two overlap, the keyword turns on mid-loop. This PR changes no line that touches ReactorEventSource, EventListener, or DiagnosticLog. I didn't keep the other failing run's output. The new test classes passed 25 back-to-back loops.
The port, supervisor, and PreviewCaptureServer test classes (94 tests) passed 3 consecutive runs after each review round.
With the fix, 15 rounds of 6 concurrent hosts running --filter Devtools_: 0 of 90 host runs failed (11,070 checks).
Release gate on the final code: dotnet restore Reactor.slnx, then dotnet build Reactor.slnx --no-restore -c Release -p:CI=true. 0 errors; the only 2 warnings are the pre-existing WIN2D0001 ones. (One earlier attempt died with MSB4166 when an MSBuild child node exited on this shared machine; rerunning with -nodereuse:false passed.)
CI on f0d05c552: 43 pass, 2 skipped by path filters. The first attempt lost Coverage (selftest-1) (and, downstream, Merged coverage) to the [Flaky] AOT Selftests: process dies mid-run at fixture 481/1459 with no TAP trailer and no not ok #1152 access violation in ConnectedAnimation_OrphanOnlyPassDoesNotCrash, before any devtools fixture had run. The same shard passed in the plain, AOT, and packaged selftest jobs, and one re-run of the failed jobs passed (details in a comment below).
Not proof on its own: a same-load comparison of 8 processes alternating the old sequence with the real helper. The old sequence failed 1 of 12,000 binds. The helper failed 0 of 12,000 and needed 0 retries, so no natural collision hit the helper during the run.
Merges cleanly with the other open PRs.git merge-tree --write-tree of this head with #1301 (0b8a172ad), #1302 (9e31a1292), and #1305 (52f468fe8) shows no conflicts, both one at a time and all together (this branch, then #1305 including #1301, then #1302). The only file changed on both sides is CHANGELOG.md. Each PR adds its own entry, and this one sits after the "Apps that reference only Microsoft.UI.Reactor" entry, so it doesn't touch the spots the others edit.
Risk / breaking changes
No public API changes; every touched type is internal.
Port can change during Start from the port the constructor probed, but only if another process took that port. Every caller reads Port after Start.
--devtools run --mcp-port N, when another process holds N, now exits with 43 and a clear message. Before, the app kept running without an MCP server. The VS and VS Code launchers don't pass --mcp-port, so this never affects them.
mur devtools now handles exit code 43 (spec 024 is updated). A port the user pinned is never moved.
An internal test seam changed signature: PreviewCaptureServer.CreateForTests(string authToken, Func<int>? probePort = null).
DevtoolsMcpServer and PreviewCaptureServer probed a free loopback port
(bind a TcpListener to port 0, read the port, release it) and bound
HttpListener to it later. Any other process could take the port in
between; with several selftest hosts on one machine the Devtools_*
fixtures failed with HttpListenerException (32). PreviewCaptureServer's
TASK-026 placeholder socket did not close the window: HTTP.sys refuses
a port that any other socket owns, so it had to be released before
Start anyway.
LoopbackHttpListener now binds with bind-and-retry: when an unpinned
bind fails because the port is taken (ERROR_SHARING_VIOLATION 32 or
ERROR_ALREADY_EXISTS 183), it probes a new port and binds again
(bounded). A pinned port is tried exactly once and fails with
LoopbackPortUnavailableException. Both servers use it, and Port is
updated before the endpoint is announced or any request is served.
mur devtools hands its auto-picked port to a child that binds it only
after dotnet run builds (and again after each reload rebuild, during
which spec 024 requires the port to stay unbound), so the child now
exits 43 when its --mcp-port is taken. The supervisor picks a new port
for an auto-picked one and fails clearly for one the user pinned.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Start now binds a fresh listener, so a second (or concurrent) Start
would bind another port and leak the first listener; HttpListener.Start
was idempotent before. A started flag, claimed under the same lock as
the listener hand-off, keeps a repeated Start a no-op. Also relax the
retry tests' exact attempt counts: a second, natural collision is a
legitimate extra retry, not a failure.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Artifact sizes for f0d05c5 vs the base branch (885a5d8).
Packages (compressed .nupkg)
Artifact
base
PR
Δ
Microsoft.UI.Reactor.nupkg
1.75 MB
1.75 MB
+332 B (+0.02%)
≈
Microsoft.UI.Reactor.Advanced.nupkg
491.7 KB
491.7 KB
+6 B (0.00%)
≈
Microsoft.UI.Reactor.Devtools.nupkg
284.0 KB
288.0 KB
+3.93 KB (+1.38%)
⚠️
Assemblies in Microsoft.UI.Reactor
Artifact
base
PR
Δ
Reactor.Analyzers.dll
373.0 KB
373.0 KB
+0 B (0.00%)
≈
Reactor.dll
2.47 MB
2.47 MB
+0 B (0.00%)
≈
Reactor.Localization.Generator.dll
16.0 KB
16.0 KB
+0 B (0.00%)
≈
Reactor.Wrappers.Abstractions.dll
10.5 KB
10.5 KB
+0 B (0.00%)
≈
Reactor.Wrappers.Generator.dll
99.5 KB
99.5 KB
+0 B (0.00%)
≈
Assemblies in Microsoft.UI.Reactor.Advanced
Artifact
base
PR
Δ
Reactor.Advanced.dll
1023.5 KB
1023.5 KB
+0 B (0.00%)
≈
Assemblies in Microsoft.UI.Reactor.Devtools
Artifact
base
PR
Δ
Microsoft.UI.Reactor.Devtools.dll
784.5 KB
788.0 KB
+3.50 KB (+0.45%)
⚠️
✅ smaller / ⚠️ larger / ≈ within noise. Sizes come from a Release dotnet pack on the CI runner: packages are the compressed .nupkg download size, assemblies the uncompressed DLL inside it. workflow run.
Under mur devtools the child's --mcp-port may be one the supervisor
picked, so "omit it" was wrong advice there; the supervisor prints the
guidance. Record the fix under [Unreleased] / Fixed (spec 024 §7).
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Coverage for f0d05c5 vs the base branch (885a5d8) — unit + selftest merged.
Metric
base
PR
Δ
Line
86.10%
86.11%
+0.01 pp
≈
Branch
77.40% (966/1248)
77.32% (965/1248)
-0.08 pp
≈
No coverage change beyond the noise floor. ✅
✅ higher / ⚠️ lower / ≈ within noise. Δ is in percentage points; coverage is unit + selftest merged (Debug x64) on the CI runner. Cobertura reports attached to the workflow run as artifacts.
The started flag was claimed before the bind finished, so a concurrent
Start returned as a no-op while the first could still retry or fail,
and Dispose could return while an in-flight Start still announced the
endpoint (banners, CAPTURE_PORT/TOKEN) for a listener it then closed.
One lifecycle lock now covers the whole HTTP start (bind, publish,
announce) and Dispose: a concurrent Start waits for the first one's
result, and once Dispose returns nothing is bound or announced. The
console writers involved take only their own locks, so there is no
lock-order inversion.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
- Dispose the probe TcpListener with `using` (TcpListener.Dispose stops it).
- ExitDevtoolsHost: try/finally instead of catch-all, so the exit always
happens and nothing is swallowed.
- Server Dispose: Close() alone (HttpListener.Dispose already runs Stop
then CleanupV2Config), catching only HttpListenerException.
- ConfigureTimeouts: catch HttpListenerException (HTTP.sys rejected a
timeout property) and PlatformNotSupportedException instead of all.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
PortThief can now hold several sockets, so the MaxAttempts test disposes
them with a using declaration instead of a manual finally loop.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
Copilot review overview
🔵 Needs a closer look
Concurrent disposal can still return before listener cleanup completes, and user-facing supervisor guidance is inconsistent.
Review effort: Balanced Findings: None
Previously missed (3)
In code that hasn't changed since last review
Dispose gate releases before cleanup, violating serialized postconditions
src/Reactor.Devtools/DevtoolsMcpServer.cs:279
Dispose releases _lifecycleGate immediately after setting _disposed, before cancellation, listener closure, lockfile deletion, and logger cleanup. A second concurrent Dispose can return while the first caller still has the port bound and the lockfile present, so the documented postcondition is not actually serialized. Keep cleanup under the lifecycle gate, or add a disposing/completed state that later callers wait on.
Concurrent Dispose can return before listener cleanup completes
Dispose publishes _disposed = true and releases _lifecycleGate before closing the listener. A second concurrent Dispose can therefore acquire the gate, return immediately, and leave the port bound until the first caller resumes, contradicting the lifecycle guarantee that once Dispose returns nothing remains bound. Keep the gate through cleanup, or track a separate disposing/completed state and make later callers wait.
Update devtools guides for supervisor exit 43 and port behavior
Please update both agent-facing devtools guides for this new supervisor contract. skills/devtools.md:93-96 and plugins/reactor/skills/reactor-devtools/SKILL.md:89-92 currently say the supervisor only handles exit 42 and presents the endpoint as unconditionally stable; they do not explain exit 43, auto-picked-port replacement, or pinned-port failure. Agents using the shipped skill otherwise cannot distinguish this intentional retry/failure path.
This issue also appears on line 321 of the same file.
Dispose released the gate right after setting _disposed, so a second
concurrent Dispose could return while the first still had the port
bound (and, for MCP, the lockfile present). Both servers now hold a
System.Threading.Lock scope for the whole Dispose, so every caller
returns only after cleanup is done. The agent-facing devtools skills
(skills/devtools.md and the plugin copy) now describe the supervisor's
exit-43 handling: pinned ports fail, auto-picked ports are replaced.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The summary says every non-reload exit code propagates, but 43 is now consumed for auto-picked ports and may relaunch the child. Update this contract to mention the port-conflict retry so it matches the implementation below.
This issue also appears on line 321 of the same file.
Dispose no longer swallows an HttpListenerException from Close silently;
it reports it on stderr like the existing listener-loop failure line.
The Supervise summary and `mur devtools --help` no longer say every
non-42 exit code propagates: 43 is handled first.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
Copilot review overview
🔵 Needs a closer look
The exit-43 path can be lost when dispatcher enqueueing fails, and the updated specification contains a contradictory exit-code rule.
Review effort: Balanced Findings: None
Previously missed (2)
In code that hasn't changed since last review
Handle failed shutdown enqueue to preserve exit code 43
src/Reactor.Devtools/DevtoolsHost.cs:703
The exit-code handshake is skipped if the dispatcher is already shutting down: TryEnqueue returns false, the callback never runs, and the supervisor may observe a normal process exit instead of 43. Check the return value and call Environment.Exit(exitCode) directly when enqueueing fails.
Clarify exit-code propagation rule for retry sentinel 43
docs/specs/024-ai-agent-devtools.md:190
This exception contradicts the preceding sentence, which still says every exit code other than 42 is propagated. Code 43 is now retried for an auto-picked port, so the supervisor contract is ambiguous. Update the preceding rule to exclude both sentinel codes.
If TryEnqueue fails because the dispatcher is already shutting down,
exit directly so the supervisor still sees 43. Spec 024's general
"any other code exits" rule now names 43 as the exception.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
Copilot review overview
🔵 Needs a closer look
The implementation is well-tested, but Windows HTTP.sys behavior, concurrent lifecycle handling, and process-exit supervision warrant final human review.
#1302 also inserts at the top of [Unreleased] / Fixed, and #1301/#1305
insert before the "Apps that reference only Microsoft.UI.Reactor" entry;
placing this entry after that one keeps all four merges clean.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
CI on f0d05c552: 41 checks pass and 2 fail. Both failures come from one crash, and it's unrelated to this PR:
Coverage (selftest-1) died with exit -1073741819 (0xC0000005, access violation) inside ConnectedAnimation_OrphanOnlyPassDoesNotCrash, which was fixture 263 of shard 1. Before the crash the run had 1,497 ok and 0 not ok, and there is no TAP trailer. That matches [Flaky] AOT Selftests: process dies mid-run at fixture 481/1459 with no TAP trailer and no not ok #1152. No Devtools or PreviewCapture fixture had run in that process yet.
Merged coverage failed only because the shard-1 report was never written (Cobertura report not found).
The same shard passed on this head in Selftests (1/2), AOT Selftests (1/2), and Packaged Selftests (MSIX) (1/2). All coverage jobs passed on 68958e46b.
Resolves a CHANGELOG.md conflict: #1309's Devtools entry and this branch's entry were both added at the same place under Fixed. Both are kept, with the landed entry first.
Co-authored-by: Copilot App <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
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
The devtools HTTP servers chose their port by probing for it: bind a
TcpListenerto127.0.0.1:0, read the port, release it. They boundHttpListenerto that port later, so another process could take it in between. When several selftest hosts run on one machine, theDevtools_*fixtures fail intermittently withHttpListenerException (32). This PR binds with bind-and-retry instead, in one helper shared byDevtoolsMcpServerandPreviewCaptureServer.mur devtoolsneeds a different fix because a child process binds its port after a build, so it gets an exit-code handshake.Why the old code raced (measured on Windows, .NET 10)
HttpListener.Startfails with 32 (ERROR_SHARING_VIOLATION) when any other socket owns the port: a listening socket on127.0.0.1or0.0.0.0, or the local end of a live connection. It fails with 183 (ERROR_ALREADY_EXISTS) when anotherHttpListener, in any process, registered the same prefix.Start. PreviewCaptureServer's TASK-026 placeholder had to be released beforeStart, so it narrowed the window without closing it. The threat model's claim that it was held untilHttpListenerbound was not accurate.Startdisposes theHttpListener, so each retry needs a new instance.TIME_WAITdoes not block HTTP.sys, andbind(0)never returns a port HTTP.sys holds.What changes
LoopbackHttpListener(new,src/Reactor.Devtools) starts anHttpListener. If the bind fails with 32 or 183, an unpinned start probes another port and binds a new listener, up to 16 attempts. A pinned port gets exactly one attempt and fails withLoopbackPortUnavailableException.DevtoolsMcpServerandPreviewCaptureServernow create and bind the listener inStart(). They setPortto the bound port before the accept loop starts, sinceIsAllowedHostcompares the Host header against it. That also happens before the endpoint is announced in the banners, thedevtools-readyline, the lockfile, andCAPTURE_PORT. The TASK-026 placeholder is removed.System.Threading.Locknow covers the whole HTTPStart(bind, publish, announce) and all ofDispose. A repeatedStart()is still a no-op, asHttpListener.Startwas. A concurrentStart()waits for the first one's result. OnceDispose()returns, nothing is bound or announced.Disposecloses the listener withClose()alone, becauseHttpListener.Disposealready runsStop()and thenCleanupV2Config().mur devtools: the supervisor probes a port and passes it to a child. The child binds it only afterdotnet runbuilds, and again after each reload rebuild. Spec 024 requires the port to stay unbound during the rebuild, so the supervisor can't hold it.43when its--mcp-portis held by another process.--mcp-portis never moved; the supervisor reports it clearly instead.Supervisemethod with injected delegates, so it can be unit-tested.43. The threat model's TASK-026 row (§7.1) is corrected, and §7.2 gains a port-TOCTOU entry. There is aCHANGELOG.mdentry under[Unreleased]/ Fixed, and the agent-facing devtools skill (skills/devtools.mdand the plugin copy) describes the43path.Linked issue / spec
Found during the devtools bug hunt; it was noted as a triage item in #1305. No issue was filed. This touches
docs/specs/024-ai-agent-devtools.md(supervisor contract) anddocs/security/threat-model.md(§7.1, §7.2).Test plan
Reproduced on
main(885a5d8) before fixingReactor.AppTests.Host --self-test --filter Devtools_runs, with background port churn. 1 of 90 host runs failed withnot ok 24 Devtools_WaitForTimeoutLoggedAsErr_CRASH - HttpListenerException: The process cannot access the file because it is being used by another process.Alone, the same filter passes.New regression tests (unit tier, headless; 29 tests)
LoopbackHttpListenerTests(9): the port is held by another socket (32) or anotherHttpListener(183), so the helper moves and serves a real request. A pinned port throws without being probed again. The helper gives up afterMaxAttempts.configureruns on every attempt, including the one that binds. The 32/183 error-code mapping.DevtoolsServerPortRaceTests(11): each server receives a probed port that another socket already holds, then serves on a new port.GET /mcpandGET /statusreturn 200, which shows thatPortwas updated before the Host-header check ran. A pinned MCP port is never moved, and the host maps that failure to exit code 43. Start after Dispose throws. A secondStartis a no-op, andDisposefrees the port. A probe seam parks the firstStartmid-retry; a concurrentStartorDisposethen stays pending until the bind completes.SupervisorLoopTests(9): a port the supervisor picked is re-picked and the child relaunched. A user-pinned port fails without moving. The supervisor gives up after 5 consecutive conflicts. A reload keeps the port and resets the conflict count. A failed build returns 2. Other exit codes propagate. The exit codes match the child's constants.These tests fail when the fix is removed
main'sDevtoolsMcpServerand added only the probe seam.McpServer_ProbedPortTakenBeforeStart_ServesOnAFreshPortthen fails withSystem.Net.HttpListenerException : The process cannot access the file because it is being used by another process.That is the production symptom.*_SecondStart_*tests fail (the port moved from 52455 to 52456).Gates
dotnet test tests/Reactor.Tests(Debug, x64), final code: 14,393 tests, 0 failed (64 skipped, all pre-existing), in the last 2 runs. Across about 20 full runs during the review rounds, two runs each had one failure. One wasReactorTraceRegressionTests.DisabledKeyword_skips_ReactorEventSource_WriteEvent_payload_marshal("leaked 61776 B ... cap: 10000"). That is an existing race between tests: the test checks once that theErrorskeyword is off, then counts its own thread's allocations over 10,000 calls. MeanwhileDocking/LayoutSerializerTestsenables everyReactorEventSourcekeyword from another test thread, and if the two overlap, the keyword turns on mid-loop. This PR changes no line that touchesReactorEventSource,EventListener, orDiagnosticLog. I didn't keep the other failing run's output. The new test classes passed 25 back-to-back loops.dotnet run --project tests/Reactor.AppTests.Host -- --self-test, on the final code: 1,555 fixtures, 7,845 checks, 0 failures. Two earlier full runs each failed onlyWindowLevel_RuntimeFlip_Topmost. That is the open flaky-test issue [Flaky] WindowLevel_RuntimeFlip_Topmost fails intermittently in the full selftest run #927: it also failed 1 of 3 runs in isolation, with its own [Flaky] WindowLevel_RuntimeFlip_Topmost fails intermittently in the full selftest run #927 diagnostic, and this change doesn't touch window code. After every review round I re-ran theDevtools_*fixtures,Hosting_PreviewCaptureServerEndpoints(a realPreviewCaptureServeron a WinUI window), andSpec051_*; all passed.--filter Devtools_: 0 of 90 host runs failed (11,070 checks).dotnet restore Reactor.slnx, thendotnet build Reactor.slnx --no-restore -c Release -p:CI=true. 0 errors; the only 2 warnings are the pre-existing WIN2D0001 ones. (One earlier attempt died withMSB4166when an MSBuild child node exited on this shared machine; rerunning with-nodereuse:falsepassed.)f0d05c552: 43 pass, 2 skipped by path filters. The first attempt lostCoverage (selftest-1)(and, downstream,Merged coverage) to the [Flaky] AOT Selftests: process dies mid-run at fixture 481/1459 with no TAP trailer and nonot ok#1152 access violation inConnectedAnimation_OrphanOnlyPassDoesNotCrash, before any devtools fixture had run. The same shard passed in the plain, AOT, and packaged selftest jobs, and one re-run of the failed jobs passed (details in a comment below).Merges cleanly with the other open PRs.
git merge-tree --write-treeof this head with #1301 (0b8a172ad), #1302 (9e31a1292), and #1305 (52f468fe8) shows no conflicts, both one at a time and all together (this branch, then #1305 including #1301, then #1302). The only file changed on both sides isCHANGELOG.md. Each PR adds its own entry, and this one sits after the "Apps that reference onlyMicrosoft.UI.Reactor" entry, so it doesn't touch the spots the others edit.Risk / breaking changes
Portcan change duringStartfrom the port the constructor probed, but only if another process took that port. Every caller readsPortafterStart.--devtools run --mcp-port N, when another process holds N, now exits with43and a clear message. Before, the app kept running without an MCP server. The VS and VS Code launchers don't pass--mcp-port, so this never affects them.mur devtoolsnow handles exit code43(spec 024 is updated). A port the user pinned is never moved.PreviewCaptureServer.CreateForTests(string authToken, Func<int>? probePort = null).