Skip to content

Harden exceptions when connecting to server - #14292

Merged
JanProvaznik merged 3 commits into
dotnet:mainfrom
JanProvaznik:harden-server-connect-exceptions
Jul 9, 2026
Merged

JanProvaznik merged 3 commits into
dotnet:mainfrom
JanProvaznik:harden-server-connect-exceptions

Conversation

@JanProvaznik

Copy link
Copy Markdown
Member

Harden exceptions when connecting to server

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 8, 2026 14:53
@JanProvaznik
JanProvaznik temporarily deployed to copilot-pat-pool July 8, 2026 14:53 — with GitHub Actions Inactive
@JanProvaznik
JanProvaznik temporarily deployed to copilot-pat-pool July 8, 2026 14:54 — with GitHub Actions Inactive
@JanProvaznik
JanProvaznik temporarily deployed to copilot-pat-pool July 8, 2026 14:54 — with GitHub Actions Inactive

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens MSBuild Server client behavior by broadening exception handling around server-state detection (mutex checks / launch mutex acquisition) so unexpected, non-critical failures don’t escape and instead trigger a structured fallback.

Changes:

  • Wrap ServerNamedMutex.WasOpen in a non-critical exception filter and treat failures as “not open”, with tracing.
  • Broaden MSBuildClient server-state exception handling from IOException to any non-critical Exception (still excluding PathTooLongException), mapping failures to UnknownServerState.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Build/BackEnd/Node/ServerNamedMutex.cs Adds exception handling + trace logging around Mutex.TryOpenExisting to avoid propagating non-critical failures.
src/Build/BackEnd/Client/MSBuildClient.cs Broadens catch filters during server-state checks / launch-mutex acquisition to avoid crashing and return UnknownServerState.

Comment thread src/Build/BackEnd/Node/ServerNamedMutex.cs
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

agentic threat detected
Threat detection flagged this output in warn mode. Manual review is REQUIRED before any follow-up automation.

Details

The threat detection results could not be parsed.

Review the workflow run logs for details.

Review — Harden exceptions when connecting to server

The approach is sound: broadening from catch (IOException) to catch (Exception when !IsCritical) is the established MSBuild idiom (used in NodeEndpointOutOfProcBase, NodePipeServer, etc.) and correctly handles the Win32Exception("Connection timed out") root cause from #7993. One concrete correctness gap and two documentation/diagnostics improvements are worth addressing.

# Dimension Verdict
22 Correctness & Edge Cases 🟠 MODERATE
18 Documentation Accuracy 🟠 MODERATE
4 Test Coverage & Completeness 🟡 MAJOR
6/14 Logging & Diagnostics / Naming 🔵 NIT

✅ 20/24 dimensions clean.

  • Correctness — WasOpen() catch (line 46) lacks && ex is not PathTooLongException, silently swallowing the exception that both MSBuildClient.cs catch blocks explicitly re-throw. See inline comment on ServerNamedMutex.cs:46.
  • Documentation — Deleted comments were the only explanation for why Exception is caught instead of IOException and why PathTooLongException is excluded. A future contributor with no context will "fix" it back. See inline comment on MSBuildClient.cs:218.
  • Test Coverage — The core fix (WasOpen returning false instead of throwing on non-IOException) has no regression test. Since Mutex.TryOpenExisting can't be injected today, a minimal approach is an integration-level test that verifies Execute() returns UnknownServerState (not a crash) when given a mutex name that causes a non-IOException. At minimum, the PathTooLongException propagation contract should be verified.
  • Logging — TryLaunchServer()'s catch emits the same "Failed to obtain the current build server state" message as Execute()'s catch, making the two failure modes indistinguishable in a trace log. See inline comment on MSBuildClient.cs:468.

Generated by Expert Code Review (on open) for #14292 · 1.3K AIC · ⊞ 30.4K

Comment thread src/Build/BackEnd/Node/ServerNamedMutex.cs Outdated
Comment thread src/Build/BackEnd/Client/MSBuildClient.cs
Comment thread src/Build/BackEnd/Client/MSBuildClient.cs
… fallback comments

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JanProvaznik
JanProvaznik enabled auto-merge (squash) July 9, 2026 10:13
@JanProvaznik
JanProvaznik merged commit 0575749 into dotnet:main Jul 9, 2026
14 checks passed
This was referenced Oct 17, 2026
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.

3 participants