Fix Unix SessionId in handshake to enable cross-terminal node reuse#13354
Merged
rainersigwald merged 1 commit intodotnet:mainfrom Mar 10, 2026
Merged
Fix Unix SessionId in handshake to enable cross-terminal node reuse#13354rainersigwald merged 1 commit intodotnet:mainfrom
rainersigwald merged 1 commit intodotnet:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
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
SessionIdonly on Windows; use0on 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). |
This was referenced Mar 10, 2026
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.
4bb1be2 to
811627c
Compare
rainersigwald
approved these changes
Mar 10, 2026
baronfel
approved these changes
Mar 10, 2026
This was referenced Mar 10, 2026
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.
Problem
On Unix,
Process.SessionIdreturns the session leader PID (fromgetsid()), 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=0on 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 keyHandshake_OnUnix_MatchesAcrossInstances— asserts matching keys across instancesBoth use
[UnixOnlyFact]per review feedback (no silent pass on Windows).Note: The MSBuildTaskHost copy (
src/MSBuildTaskHost/) usesProcess.SessionIddirectly but only runs on .NET Framework/Windows, so it's unaffected.Split from #13336 per reviewer request.