msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

[Feature Request]: MSBuild Server Identifier

Open hknielsen opened this issue 2 years ago • 9 comments

Summary

Server reuse across clones, can lead to issues when Shutdown, leading to errors.

Background and Motivation

When having multiple Clones of the same repository using MSBuild Server for speeding up compilation, we end up in situations where the MSBuild Server gets shutdown from the other clone, while a compilation is ongoing, resulting in errors because of Server Shutdown.

Our setup:

  • Each clone have its own copy of MSBuild copied into it, and execute MSBuild Server.

Proposed Feature

Add an Identifier to the started server + nodes started by the server, so repositories can't interfere with each other. It would be optimal if:

  • The Identifier could be passed as an argument or a new env var SharedId
  • The Identifier would be additive to the current CommunicationsUtilities.GetHandshakeOptions so it would work as today if no extra identifier was added.
  • Add the public api to MSBuildClient to support MSBuild Server Identifier.
  • Possible to use the same SharedId to pass to Roslyn's similar concept SharedCompilationId

This would make it easier to control multiple msbuild servers that can't interfere with eachother.

Alternative Designs

The MSBuild Server is identified with the location, so if we have two copies of MSBuild, each would have a unique identity and MSBuild Server + Nodes.

hknielsen avatar Jan 29 '24 22:01 hknielsen

Seems related to https://github.com/dotnet/sdk/issues/9303 and https://github.com/dotnet/sdk/issues/20183. Could this use the same SharedCompilationId property as Roslyn?

KalleOlaviNiemitalo avatar Jan 30 '24 02:01 KalleOlaviNiemitalo

Seems related to dotnet/sdk#9303 and dotnet/sdk#20183. Could this use the same SharedCompilationId property as Roslyn?

It would make alot of sense that all MSBuild nodes and Roslyn would use the same Identifier, passing along the MSBuild SharedId to Roslyn.

hknielsen avatar Jan 30 '24 08:01 hknielsen

@KalleOlaviNiemitalo updated the proposal to use the same Shared-Id between Roslyn and MSBuild

hknielsen avatar Jan 30 '24 08:01 hknielsen

@hknielsen sorry, I can't repro your issue as the following steps. Did you repro you issue in your specified repo? or is there anything that I missed?

  1. Enable MSBuild Server with DOTNET_CLI_USE_MSBUILD_SERVER = 1
  2. Clone two copies of msbuild repos and execute dotnet build MSBuild.sln
  3. dotnet build-server shutdown when one build is done and the other is still going.

JaynieBai avatar Feb 27 '24 06:02 JaynieBai

@JaynieBai We were seeing it randomly in CI. Basically it was related to rebuilds on multiple clones using the same msbuild server, where one finished and shutsdown the server.

hknielsen avatar Apr 03 '24 11:04 hknielsen

@hknielsen and to be clear: you are explicitly setting DOTNET_CLI_USE_MSBUILD_SERVER in your CI jobs?

rainersigwald avatar Apr 05 '24 19:04 rainersigwald

@rainersigwald - yeah, we are setting the env var to enable the MSBuild Servier. And calling shutdown when done. We were also not only using this on CI, so when we are done building, we cleanup resources, including shutdown the MSBuild Server

hknielsen avatar Apr 06 '24 19:04 hknielsen

Roslyn/Razor are also hitting similar issues with the Razor compiler server and the build-server shutdown command. cc @jaredpar - it would be cool if we could find a reusable solution for our different servers.

baronfel avatar Apr 06 '24 21:04 baronfel

I agree that we need to find a reusable solution for our different servers. Right now we're all solving the same problem but in different ways which each have their own flaws.

jaredpar avatar Apr 08 '24 16:04 jaredpar