Skip to content

common: Fix Windows CPU affinity runtime detection - #850

Merged
AlexWFMS merged 4 commits into
mainfrom
fix/windows-runtime-affinity
Nov 13, 2026
Merged

AlexWFMS merged 4 commits into
mainfrom
fix/windows-runtime-affinity

Conversation

@AlexWFMS

@AlexWFMS AlexWFMS commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The #if WINDOWS directive prevented the affinity assignment from being compiled into the binary. The plain net8.0, net9.0, and net10.0 targets do not define WINDOWS, even when published for win-x64. Only the #else branch was compiled, so the method always threw PlatformNotSupportedException, including on Windows.

.NET already provides runtime OS detection. Replace the compile-time directive with its built-in OperatingSystem.IsWindows() check so Windows reaches the affinity assignment. Other platforms still receive the same exception.

This PR changes only the runtime guard. It does not change target frameworks, compilation symbols, or process lifecycle handling.

Validation

  • Existing ProcessProxy and ProcessAffinity tests: 46 passed.
  • Common Release builds for net8.0, net9.0, and net10.0: no warnings or errors.
  • Normal self-contained win-x64 Main publish with analyzers enabled: passed.
  • Real child-process probes on Azure Windows Server 2022 and 2025 reproduced the baseline exception. With the fix, both applied a CPU selected from the available affinity mask and read back the requested mask.
  • Invalid zero masks still produce native error 87. The Linux probe still rejects the operation.

Workload smoke follow-up

Short, single-iteration workload runs were also executed on Windows Server 2022 and 2025:

  • Example affinity workload and ASP.NET with Bombardier: passed on both. Actual process readback confirmed server/workload mask 1 and client mask 2. ASP.NET returned successful HTTP responses.
  • Orchard with Bombardier: actual server/client masks were correctly applied on both, but the constrained runs received no HTTP responses. The client reported connections closing before the first response byte. These are not full workload passes, despite exit code 0.
  • Orchard controls with affinity disabled returned successful HTTP responses on both. They reused warm build/application state, so this does not isolate CPU allocation from cold-start or readiness effects.

The Orchard case adapts the Linux-only Wrk profile to use Bombardier on Windows. The HTTP failure remains unresolved and is not claimed to be a lifecycle fix or an unrelated issue.

The smoke scripts and captures remain outside the repository. All dedicated Azure test resources were deleted.

Use a runtime Windows check so plain .NET targets can set process affinity on Windows while preserving rejection on other platforms.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@AlexWFMS
AlexWFMS merged commit 3de6e0f into main Nov 13, 2026
5 checks passed
@AlexWFMS
AlexWFMS deleted the fix/windows-runtime-affinity branch November 13, 2026 18:20
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