dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.17k stars 1.34k forks source link

[Feature Request]: MSBuild Server Identifier #9692

Open hknielsen opened 5 months ago

hknielsen commented 5 months ago

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:

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:

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.

KalleOlaviNiemitalo commented 5 months ago

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?

hknielsen commented 5 months ago

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 commented 5 months ago

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

JaynieBai commented 4 months ago

@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.
hknielsen commented 3 months ago

@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.

rainersigwald commented 2 months ago

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

hknielsen commented 2 months ago

@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

baronfel commented 2 months ago

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.

jaredpar commented 2 months ago

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.