Skip to content

Fix Unix SessionId in handshake to enable cross-terminal node reuse#13354

Merged
rainersigwald merged 1 commit intodotnet:mainfrom
JakeRadMSFT:fix/unix-session-id
Mar 10, 2026
Merged

Fix Unix SessionId in handshake to enable cross-terminal node reuse#13354
rainersigwald merged 1 commit intodotnet:mainfrom
JakeRadMSFT:fix/unix-session-id

Conversation

@JakeRadMSFT
Copy link
Copy Markdown
Member

Problem

On Unix, Process.SessionId returns the session leader PID (from getsid()), which differs per terminal. This prevents MSBuild nodes launched from one terminal from being reused by builds in another terminal — each terminal effectively gets its own set of idle nodes.

Fix

Use SessionId=0 on non-Windows platforms. Unix doesn't need RDP-style session isolation, so 0 is safe and enables cross-terminal node reuse.

Tests

  • Handshake_OnUnix_SessionIdIsZero — asserts the SessionId component is 0 in the key
  • Handshake_OnUnix_MatchesAcrossInstances — asserts matching keys across instances

Both use [UnixOnlyFact] per review feedback (no silent pass on Windows).

Note: The MSBuildTaskHost copy (src/MSBuildTaskHost/) uses Process.SessionId directly but only runs on .NET Framework/Windows, so it's unaffected.

Split from #13336 per reviewer request.

Copilot AI review requested due to automatic review settings March 10, 2026 06:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 updates MSBuild’s node handshake behavior on Unix-like platforms to avoid terminal-specific session IDs, enabling out-of-proc nodes started in one terminal to be reused by builds started from another terminal.

Changes:

  • Populate the handshake SessionId only on Windows; use 0 on Unix-like platforms to avoid per-terminal session leader PID differences.
  • Add Unix-only unit tests intended to validate the updated handshake behavior.

Reviewed changes

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

File Description
src/Shared/CommunicationsUtilities.cs Gates handshake SessionId retrieval to Windows to enable cross-terminal node reuse on Unix-like OSes.
src/Build.UnitTests/BackEnd/UnixNodeReuseFixes_Tests.cs Adds Unix-only tests around handshake key/session-id behavior (needs adjustment to provide meaningful coverage and avoid brittle string parsing).

Comment thread src/Build.UnitTests/BackEnd/UnixNodeReuseFixes_Tests.cs Outdated
Comment thread src/Build.UnitTests/BackEnd/UnixNodeReuseFixes_Tests.cs
On Unix, Process.SessionId returns the session leader PID (from getsid()),
which differs per terminal. This prevents nodes launched from one terminal
from being reused by builds in another terminal. On Windows, SessionId
correctly differentiates RDP sessions.

Fix: Use SessionId=0 on non-Windows platforms, since Unix doesn't need
RDP-style session isolation. This restores effective node reuse across
terminals on macOS and Linux.

Tests use [UnixOnlyFact] and directly assert SessionId=0 in the key.

Note: The MSBuildTaskHost copy (src/MSBuildTaskHost/) has the same pattern
but only runs on .NET Framework/Windows, so it's not affected.
@JakeRadMSFT JakeRadMSFT force-pushed the fix/unix-session-id branch from 4bb1be2 to 811627c Compare March 10, 2026 07:02
@rainersigwald rainersigwald merged commit 6a4c26f into dotnet:main Mar 10, 2026
10 checks passed
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.

4 participants