roslyn: MSBuildWorkspace.OpenSolutionAsync hangs indefinitely on 4.9.0+ in Windows 2022 Azure CI/CD
Version Used:
<PackageReference Include="Microsoft.Build.Locator" Version="1.7.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.11.0" />
Steps to Reproduce:
- Writing a dotnet tool that opens a solution to run through all projects. This code hangs indefinitely:
MSBuildLocator.RegisterDefaults();
using var workspace = MSBuildWorkspace.Create();
workspace.WorkspaceFailed += (_, args) => Console.WriteLine(args.Diagnostic.Message);
var solution = await workspace.OpenSolutionAsync(solutionPath);
Expected Behavior:
The code should move past OpenSolutionAsync, returning the workspace and finish running the application.
Actual Behavior:
Specifically on Azure Pipelines, latest Windows 2022, with .NET 9:
jobs:
- job: BuildWindows
displayName: 'Windows Server 2022'
pool:
vmImage: 'windows-latest'
steps:
- task: UseDotNet@2
displayName: 'Install .NET 9'
inputs:
useGlobalJson: true
The code above hangs indefinitely.
Link to the PR in our repo that replicates this: https://github.com/modernuo/SerializationGenerator/pull/43/files#diff-f2b522070e7bfd744704829ee17ae88ea259383f12f3a45fb2d860a2a0c3e19c
In that PR, I also tried to clean up any possible deadlocks, but nothing changed.
Repo that uses this tool and it’s PR:
The azure pipelines yaml file we use is here: https://github.com/modernuo/ModernUO/pull/1984/files#diff-7915b9b726a397ae7ba6af7b9703633d21c031ebf21682f3ee7e6a4ec52837a5
The tool is run through a cmd file as part of the build process: https://github.com/modernuo/ModernUO/blob/1d08572926ad3e6376fbebb1ec169624f9cfdb74/publish.cmd#L46
I cannot replicate this locally on Windows 11, nor on other operating systems. If I had to guess, it is related to how .NET is installed/path’d on that docker
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 34 (21 by maintainers)
Commits related to this issue
- Report errors processing messages from the build host (#76252) Related to https://github.com/dotnet/roslyn/issues/75967 Previously, any errors processing messages would just cause an inifnite han... — committed to dotnet/roslyn by dibarbet 2 years ago
- Use named pipes to connect to the BuildHost process. (#76259) Suggested in https://github.com/dotnet/roslyn/issues/75967#issuecomment-2515889705 — committed to dotnet/roslyn by JoeRobich 2 years ago
@dibarbet @jasonmalinowski Please see #76259
Closing - I believe the only thing left is for this to flow into real packages (17.13) which should happen soon with the regular flow.
Great to hear!
Unfortunately this is unlikely to meet the bar for servicing the 4.12 packages - it will have to go out with the normal 4.13 versions. However if you’re happy with how the version I linked above is working, you can continue to use it. It’s an official Roslyn build, just not the final one published to nuget.org.
If MSBuild itself is hanging in a regular build this won’t help. This only affects loading projects/slns with Roslyn’s MSBuildWorkspace.
I may not have time today, but I can definitely try tomorrow.
@kamronbatman would you be able to try package version 4.13.0-3.24605.1 (you will need to add the dotnet-tools azdo feed as they are not published to nuget.org). This should have the both the changes to observe failures and the named pipe fix.
Made some progress on this today. It looks like if anything writes to stdout from the build host process, we will see an indefinite hang. This includes a simple
Console.Write(or related), any process exception message (for example when an OOM is thrown, an error message is written to the console), any MSBuild unhandled exception, and possibly other scenarios.The cause appears to be a json serialization exception thrown here - https://github.com/dotnet/roslyn/blob/main/src/Workspaces/Core/MSBuild/Rpc/RpcClient.cs#L52 which ends up never being observed, and the requests infinitely hang.
@jasonmalinowski I have a draft change here to at least observe the failures - https://github.com/dotnet/roslyn/pull/76252 . However I think we need to do what we did in the LSP server - switch to named pipes. stdin/stdout is too prone to issues like this.
@kamronbatman - I’m fairly confident this is related, but not 100% sure. I’ll reply back here once my first changes merge and we have official packages you can use. While it won’t fix it, it should at least tell us if and what the erroring stdout message is.
I will have to get back to this next week. I think the next step is to create a similarly spec’d VM to see if I can reproduce the issue outside of azure pipelines.
Not sure if also makes a difference, but it’s 2 vCPU in Azure instead of 4 for GitHub Actions.
Regarding the indefinite hang on Linux, I’ll try to get more info. What I know for now is it is also a 2 vCPU machine with 4GB, manually set up with debian and .net 8 on GCP. Increasing the machine’s CPU/ram to 4 vCPU and 8GM ram by choosing another instance type and rebooting the machine resolves the issue. It hangs while building the projects, not running the tool I made.
Also let me know if there is anything else I can do to help move this further along. Hope everyone has a great holiday this week!
Unfortunately hit another snag that I didn’t realize beforehand - the processId from launching the dotnet tool is unfortunately only a wrapper around another process that is actually running the tool. And there are additionally a further couple of processes involved in the MSBuildWorkspace project loading. The previous dumps only captured the wrapper process which doesn’t have anything really useful in it.
Procdump is definitely not very ergonomic to use for this case, but unfortunately I don’t think there’s anything better 😆 . I’ve modified the dump capture to instead look for processes with matching command line arguments. Hopefully this is the last iteration… https://github.com/dibarbet/ModernUO/commit/0946e25f046147ccc9dd1183efea23cd825e9b6e
@dibarbet I sent you a link to the dumps via discord.
Thanks - it looks like procdump isn’t detecting a hang and not collecting any dumps.
Try this instead - it will collect a dump every 5 seconds up to 5 total. You may have to adjust the time depending on how long it takes to get to the broken state - https://github.com/dibarbet/ModernUO/commit/14ea3c62984ec82df3ef6101af7384439aac865e
@kamronbatman try something similar to this - https://github.com/dibarbet/ModernUO/commit/202ae64adeeb901308010e4f4fcad1dfbc7270d8
You may have to tweak it a bit to make sure it captures the dump on hang and uploads correctly.
It is incredibly mystifying that the github actions run passes, but fails on AzDo with the exact same image.
@kamronbatman interesting note here - I took your .NET9 PR and ran it against github actions - appeared to have no issues there https://github.com/dibarbet/ModernUO/tree/actions_only - I don’t have access to an azure pipeline to run it against. I’ll see if I can figure out procdump instructions tomorrow.