-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Implement out-of-proc RAR node lifecycle #11383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 14 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
6e215d4
Implement out-of-proc RAR node lifecycle
ccastanedaucf 4b7e5b1
Fix CI test (bump EngineServices version)
ccastanedaucf 6613006
Fix connection logic for Node reuse scenarios
ccastanedaucf eb00e2f
Rebase + fix missing ValueTask (reference System.Threading.Channels)
ccastanedaucf 0ec1d0b
Switch server to async APIs from shared IPC
ccastanedaucf 4a30ed7
Move channels under netstandard itemgroup
ccastanedaucf 4add6ce
Changes for rebase (won't compile till !11650 is merged)
ccastanedaucf ab8eb4b
Rename / flip out-of-proc override
ccastanedaucf a37ff7f
Condition multi-instance pipe flag, assert all succeed
ccastanedaucf 2b8aecd
Remove fire-and-forget TODO
ccastanedaucf 654f4ec
Seal types
ccastanedaucf 096916f
Startup perf: Fire and forget launcher
ccastanedaucf fb8fb89
Startup perf: Skip expensive process ID check in ServerNodeHandshake
ccastanedaucf df240e1
Accessor oopsie
ccastanedaucf 2dc7fef
Disposal comment
ccastanedaucf 4e68b55
Propogate UnauthorizedAccessException
ccastanedaucf f60d135
Trace endpoint cancellation
ccastanedaucf c6a90cf
Change prop 'Disabled' to 'Allow'
ccastanedaucf 7c2d80f
Startup perf: Pre-run RAR static resource intializers
ccastanedaucf a21a685
Startup perf: Lift common state initialization to host node
ccastanedaucf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
79 changes: 79 additions & 0 deletions
79
src/Build/BackEnd/Components/Communications/RarNodeLauncher.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using Microsoft.Build.Internal; | ||
| using Microsoft.Build.Shared; | ||
| using Microsoft.Build.Shared.FileSystem; | ||
|
|
||
| namespace Microsoft.Build.BackEnd | ||
| { | ||
| internal sealed class RarNodeLauncher | ||
| { | ||
| private readonly INodeLauncher _nodeLauncher; | ||
|
|
||
| private readonly string _pipeName; | ||
|
|
||
| internal RarNodeLauncher(INodeLauncher nodeLauncher) | ||
| { | ||
| _nodeLauncher = nodeLauncher; | ||
| _pipeName = NamedPipeUtil.GetRarNodePipeName(new(HandshakeOptions.None)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a new MSBuild process with the RAR nodemode. | ||
| /// </summary> | ||
| public bool Start() | ||
| { | ||
| if (IsRarNodeRunning()) | ||
| { | ||
| CommunicationsUtilities.Trace("Existing RAR node found."); | ||
| return true; | ||
| } | ||
|
|
||
| CommunicationsUtilities.Trace("Launching RAR node..."); | ||
|
|
||
| try | ||
| { | ||
| LaunchNode(); | ||
| } | ||
| catch (NodeFailedToLaunchException ex) | ||
| { | ||
| CommunicationsUtilities.Trace("Failed to launch RAR node: {0}", ex); | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| private bool IsRarNodeRunning() | ||
| { | ||
| // Determine if the node is running by checking if the expected named pipe exists. | ||
| if (NativeMethodsShared.IsWindows) | ||
| { | ||
| const string NamedPipeRoot = @"\\.\pipe\"; | ||
|
|
||
| // File.Exists() will crash the pipe server, as the underlying Windows APIs have undefined behavior | ||
| // when used with pipe objects. Enumerating the pipe directory avoids this issue. | ||
| IEnumerable<string> pipeNames = FileSystems.Default.EnumerateFiles(NamedPipeRoot); | ||
|
|
||
| return pipeNames.Contains(Path.Combine(NamedPipeRoot, _pipeName)); | ||
SimaTian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| else | ||
| { | ||
| // On Unix, named pipes are implemented via sockets, and the pipe name is simply the file path. | ||
| return FileSystems.Default.FileExists(_pipeName); | ||
| } | ||
| } | ||
|
|
||
| private void LaunchNode() | ||
| { | ||
| string msbuildLocation = BuildEnvironmentHelper.Instance.CurrentMSBuildExePath; | ||
| string commandLineArgs = string.Join(" ", ["/nologo", "/nodemode:3"]); | ||
| _ = _nodeLauncher.Start(msbuildLocation, commandLineArgs, nodeId: 0); | ||
JanProvaznik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.