Skip to content
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

Dotnet build hangs at CoreCompile when specific NuGet package referenced #112502

Closed
Forgind opened this issue Dec 20, 2024 · 22 comments · Fixed by #111937
Closed

Dotnet build hangs at CoreCompile when specific NuGet package referenced #112502

Forgind opened this issue Dec 20, 2024 · 22 comments · Fixed by #111937

Comments

@Forgind
Copy link
Member

Forgind commented Dec 20, 2024


Issue moved from dotnet/sdk#45036


From @fabianoliver on Friday, November 22, 2024 10:10:28 AM

Describe the bug

When using SDK 9.0.100, building any project that references "ReactiveUI.SourceGenerations" version 1.1.31 hangs forever at the "CoreCompile" stage. Building the same project using SDK 8.0.100 works well.

Please feel free to close this issue if you reckon the package itself is at fault of course. I'm raising this here though as I would think that building this with a different SDK version "should" not be able to break the referenced package / source generator in any way?

To Reproduce

Build an empty project with the following csproj

<PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
    <PackageReference Include="ReactiveUI.SourceGenerators" Version="1.1.31" PrivateAssets="all" />
</ItemGroup>
@Forgind
Copy link
Member Author

Forgind commented Dec 20, 2024

I'm not 100% sure what's going on here, as I don't understand how adding a PackageReference could possibly make something hang, but I don't see how it's connected to the SDK, so since it's hanging in the CoreCompile stage, I'm tentatively moving it to roslyn for a first look.

@CyrusNajmabadi
Copy link
Member

Presumably an SG is running and has an infinite loop or something (or just takes a really really long time). Best is to open this in a profiler or debugger and see what stacks it is in when it appears to not be making progress.

@Youssef1313
Copy link
Member

Youssef1313 commented Dec 25, 2024

That's very likely an issue on https://github.com/reactiveui/ReactiveUI.SourceGenerators

@fabianoliver I can't repro by simply adding the package reference to a blank console app.

@fabianoliver
Copy link

fabianoliver commented Dec 27, 2024

@Youssef1313 Thanks for having a look. Strange, I've run this on a simple blank console app as well with the csproj file above.
Maybe worth noting: More recent versions of this library work fine, the particular one above does cause a freeze for me though.

I've tried on 2 independent systems and ran into that issue on both of them. I'm running on win10 (though I first ran into this issue via CI build on an unix image) & have attached dotnet --info for reference. I'm trying the build via simple cmd-line execution of "dotnet build".

For reference, I've attached a debugger while it appears to be stuck on CoreCompile - as per @CyrusNajmabadi 's suggestion, stack traces of all threads attached as well, in case that helps (though not sure if there's any child processes spawned that might have more relevant traces to look at?).

Unfortunately, I agree it feels very much like a potential bug of the library, so the end result might be rather "boring" here; just thought I'd flag this out of caution as personally, I could think of many ways to make source generators hang, but a lot less ways to make them hang just with specific NET SDK versions

dotnet-info.txt
build-stacktrace.txt

@Youssef1313
Copy link
Member

Thank you. I'm able to reproduce. I can see one of the threads appear to be stuck here. I can't see any reason this can happen or be specific to SDK version.

OS Thread Id: 0x1470
        Child SP               IP Call Site
0000004E5563D958 00007ffc576a3374 [HelperMethodFrame: 0000004e5563d958]
0000004E5563DA80 00007FFBB146A3C5 ReactiveUI.SourceGenerators.CodeAnalyzers.PropertyToReactiveFieldAnalyzer.get_SupportedDiagnostics() [c:\temp\releaser\ReactiveUI.SourceGenerators\src\ReactiveUI.SourceGenerators\CodeAnalyzers\PropertyToReactiveFieldAnalyzer.cs @ 29]
0000004E5563DAC0 00007FFC0C2C0F4F Microsoft.CodeAnalysis.Diagnostics.AnalyzerManager+AnalyzerExecutionContext+<>c__DisplayClass21_0.<ComputeDiagnosticDescriptors_NoLock>b__0(System.Object) [/_/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerManager.AnalyzerExecutionContext.cs @ 299]
0000004E5563DB10 00007FFC0C3A9CBB Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[[System.__Canon, System.Private.CoreLib]](Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer, System.Action`1<System.__Canon>, System.__Canon, System.Nullable`1<Microsoft.CodeAnalysis.Diagnostics.AnalysisContextInfo>, System.Threading.CancellationToken) [/_/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerExecutor.cs @ 1182]
0000004E5563DBA0 00007FFC0C3A9B08 Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows[[System.__Canon, System.Private.CoreLib]](Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer, System.Action`1<System.__Canon>, System.__Canon, System.Nullable`1<Microsoft.CodeAnalysis.Diagnostics.AnalysisContextInfo>, System.Threading.CancellationToken) [/_/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerExecutor.cs @ 1163]
0000004E5563DC50 00007FFC0C2AA97B Microsoft.CodeAnalysis.Diagnostics.AnalyzerManager+AnalyzerExecutionContext.ComputeDiagnosticDescriptors_NoLock(Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer, Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor, System.Threading.CancellationToken) [/_/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerManager.AnalyzerExecutionContext.cs @ 295]
0000004E5563DD10 00007FFC0C3ADF1D Microsoft.CodeAnalysis.Diagnostics.AnalyzerManager+AnalyzerExecutionContext.GetOrComputeDescriptors[[System.__Canon, System.Private.CoreLib]](System.Collections.Immutable.ImmutableArray`1<System.__Canon> ByRef, System.Func`4<Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer,Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor,System.Threading.CancellationToken,System.Collections.Immutable.ImmutableArray`1<System.__Canon>>, Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer, Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor, System.Object, System.Threading.CancellationToken) [/_/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerManager.AnalyzerExecutionContext.cs @ 277]
0000004E5563DD90 00007FFC0C2AA7FA Microsoft.CodeAnalysis.Diagnostics.AnalyzerManager+AnalyzerExecutionContext.GetOrComputeDiagnosticDescriptors(Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer, Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor, System.Threading.CancellationToken) [/_/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerManager.AnalyzerExecutionContext.cs @ 250]
0000004E5563DE10 00007FFC0C23239C Microsoft.CodeAnalysis.Diagnostics.AnalyzerManager.IsDiagnosticAnalyzerSuppressed(Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer, Microsoft.CodeAnalysis.CompilationOptions, System.Func`2<Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer,Boolean>, Microsoft.CodeAnalysis.Diagnostics.SeverityFilter, System.Func`2<Microsoft.CodeAnalysis.DiagnosticDescriptor,Boolean>, System.Func`2<Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer,System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.DiagnosticDescriptor>>, System.Func`2<Microsoft.CodeAnalysis.Diagnostics.DiagnosticSuppressor,System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.SuppressionDescriptor>>, System.Threading.CancellationToken) [/_/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerManager.cs @ 356]
0000004E5563DF20 00007FFC0C2A70AF Microsoft.CodeAnalysis.Diagnostics.AnalyzerDriver+<GetAnalyzerActionsAsync>d__150.MoveNext() [/_/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerDriver.cs @ 2035]
0000004E5563E3F0 00007FFBB1B3B819 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.ValueTuple`2[[Microsoft.CodeAnalysis.Diagnostics.AnalyzerActions, Microsoft.CodeAnalysis],[System.__Canon, System.Private.CoreLib]], System.Private.CoreLib],[Microsoft.CodeAnalysis.Diagnostics.AnalyzerDriver+<GetAnalyzerActionsAsync>d__150, Microsoft.CodeAnalysis]].ExecutionContextCallback(System.Object) [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs @ 292]
0000004E5563E420 00007FFC067EC304 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) [/_/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs @ 179]
0000004E5563E490 00007FFBB1B3B631 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.ValueTuple`2[[Microsoft.CodeAnalysis.Diagnostics.AnalyzerActions, Microsoft.CodeAnalysis],[System.__Canon, System.Private.CoreLib]], System.Private.CoreLib],[Microsoft.CodeAnalysis.Diagnostics.AnalyzerDriver+<GetAnalyzerActionsAsync>d__150, Microsoft.CodeAnalysis]].MoveNext(System.Threading.Thread)
0000004E5563E540 00007FFBB1B3B46A System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.ValueTuple`2[[Microsoft.CodeAnalysis.Diagnostics.AnalyzerActions, Microsoft.CodeAnalysis],[System.__Canon, System.Private.CoreLib]], System.Private.CoreLib],[Microsoft.CodeAnalysis.Diagnostics.AnalyzerDriver+<GetAnalyzerActionsAsync>d__150, Microsoft.CodeAnalysis]].MoveNext() [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs @ 350]
0000004E5563E570 00007FFC0680EF5D System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Runtime.CompilerServices.IAsyncStateMachineBox, Boolean) [/_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskContinuation.cs @ 795]
0000004E5563E5D0 00007FFC06809779 System.Threading.Tasks.Task.RunContinuations(System.Object) [/_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs @ 3453]
0000004E5563E680 00007FFBB1B3B41F System.Threading.Tasks.Task`1[[Microsoft.CodeAnalysis.Diagnostics.AnalyzerActions, Microsoft.CodeAnalysis]].TrySetResult(Microsoft.CodeAnalysis.Diagnostics.AnalyzerActions) [/_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs @ 387]
0000004E5563E6D0 00007FFBB1B3B2F1 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[Microsoft.CodeAnalysis.Diagnostics.AnalyzerActions, Microsoft.CodeAnalysis]].SetExistingTaskResult(System.Threading.Tasks.Task`1<Microsoft.CodeAnalysis.Diagnostics.AnalyzerActions>, Microsoft.CodeAnalysis.Diagnostics.AnalyzerActions) [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs @ 494]
0000004E5563E7B0 00007FFBB1B3B20B System.Runtime.CompilerServices.AsyncValueTaskMethodBuilder`1[[Microsoft.CodeAnalysis.Diagnostics.AnalyzerActions, Microsoft.CodeAnalysis]].SetResult(Microsoft.CodeAnalysis.Diagnostics.AnalyzerActions) [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilderT.cs @ 54]
0000004E5563E890 00007FFC0C2AB838 Microsoft.CodeAnalysis.Diagnostics.AnalyzerManager+<GetAnalyzerActionsAsync>d__12.MoveNext() [/_/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerManager.cs @ 178]
0000004E5563EA20 00007FFBB1B2B2D3 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[Microsoft.CodeAnalysis.Diagnostics.AnalyzerActions, Microsoft.CodeAnalysis],[Microsoft.CodeAnalysis.Diagnostics.AnalyzerManager+<GetAnalyzerActionsAsync>d__12, Microsoft.CodeAnalysis]].ExecutionContextCallback(System.Object) [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs @ 292]
0000004E5563EA60 00007FFC067EC304 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) [/_/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs @ 179]
0000004E5563EAD0 00007FFBB1B2B176 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[Microsoft.CodeAnalysis.Diagnostics.AnalyzerActions, Microsoft.CodeAnalysis],[Microsoft.CodeAnalysis.Diagnostics.AnalyzerManager+<GetAnalyzerActionsAsync>d__12, Microsoft.CodeAnalysis]].MoveNext(System.Threading.Thread) [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs @ 366]
0000004E5563EB40 00007FFBB1B3B0DA System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[Microsoft.CodeAnalysis.Diagnostics.AnalyzerActions, Microsoft.CodeAnalysis],[Microsoft.CodeAnalysis.Diagnostics.AnalyzerManager+<GetAnalyzerActionsAsync>d__12, Microsoft.CodeAnalysis]].MoveNext() [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs @ 350]
0000004E5563EB70 00007FFC0680EF5D System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Runtime.CompilerServices.IAsyncStateMachineBox, Boolean) [/_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskContinuation.cs @ 795]
0000004E5563EBD0 00007FFC06809779 System.Threading.Tasks.Task.RunContinuations(System.Object) [/_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs @ 3453]
0000004E5563EC80 00007FFC06ACE571 System.Threading.Tasks.Task`1[[System.__Canon, System.Private.CoreLib]].TrySetResult(System.__Canon) [/_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs @ 387]
0000004E5563ECD0 00007FFC06AD8E4D System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, System.Private.CoreLib]].SetExistingTaskResult(System.Threading.Tasks.Task`1<System.__Canon>, System.__Canon) [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs @ 494]
0000004E5563ED10 00007FFC0C2ABA02 Microsoft.CodeAnalysis.Diagnostics.AnalyzerManager+<GetCompilationAnalysisScopeAsync>d__6.MoveNext() [/_/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerManager.cs @ 65]
0000004E5563EDB0 00007FFBB1B3B096 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.__Canon, System.Private.CoreLib],[Microsoft.CodeAnalysis.Diagnostics.AnalyzerManager+<GetCompilationAnalysisScopeAsync>d__6, Microsoft.CodeAnalysis]].ExecutionContextCallback(System.Object) [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs @ 292]
0000004E5563EDE0 00007FFC067EC304 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) [/_/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs @ 179]
0000004E5563EE50 00007FFBB1B3AEDE System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.__Canon, System.Private.CoreLib],[Microsoft.CodeAnalysis.Diagnostics.AnalyzerManager+<GetCompilationAnalysisScopeAsync>d__6, Microsoft.CodeAnalysis]].MoveNext(System.Threading.Thread)
0000004E5563EF00 00007FFBB1B3AD7A System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.__Canon, System.Private.CoreLib],[Microsoft.CodeAnalysis.Diagnostics.AnalyzerManager+<GetCompilationAnalysisScopeAsync>d__6, Microsoft.CodeAnalysis]].MoveNext() [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs @ 350]
0000004E5563EF30 00007FFC0680EF5D System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Runtime.CompilerServices.IAsyncStateMachineBox, Boolean) [/_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskContinuation.cs @ 795]
0000004E5563EF90 00007FFC06809779 System.Threading.Tasks.Task.RunContinuations(System.Object) [/_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs @ 3453]
0000004E5563F040 00007FFC06ACE571 System.Threading.Tasks.Task`1[[System.__Canon, System.Private.CoreLib]].TrySetResult(System.__Canon) [/_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs @ 387]
0000004E5563F090 00007FFC06AD8E4D System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, System.Private.CoreLib]].SetExistingTaskResult(System.Threading.Tasks.Task`1<System.__Canon>, System.__Canon) [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs @ 494]
0000004E5563F0D0 00007FFC0C2ABCB6 Microsoft.CodeAnalysis.Diagnostics.AnalyzerManager+<GetCompilationAnalysisScopeCoreAsync>d__7.MoveNext() [/_/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerManager.cs @ 89]
0000004E5563F1A0 00007FFBB1B3AD36 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.__Canon, System.Private.CoreLib],[Microsoft.CodeAnalysis.Diagnostics.AnalyzerManager+<GetCompilationAnalysisScopeCoreAsync>d__7, Microsoft.CodeAnalysis]].ExecutionContextCallback(System.Object) [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs @ 292]
0000004E5563F1D0 00007FFC067EC304 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) [/_/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs @ 179]
0000004E5563F240 00007FFBB1B3AB7E System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.__Canon, System.Private.CoreLib],[Microsoft.CodeAnalysis.Diagnostics.AnalyzerManager+<GetCompilationAnalysisScopeCoreAsync>d__7, Microsoft.CodeAnalysis]].MoveNext(System.Threading.Thread)
0000004E5563F2F0 00007FFBB1B3AA1A System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.__Canon, System.Private.CoreLib],[Microsoft.CodeAnalysis.Diagnostics.AnalyzerManager+<GetCompilationAnalysisScopeCoreAsync>d__7, Microsoft.CodeAnalysis]].MoveNext() [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs @ 350]
0000004E5563F320 00007FFC0680EF5D System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Runtime.CompilerServices.IAsyncStateMachineBox, Boolean) [/_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskContinuation.cs @ 795]
0000004E5563F380 00007FFC06809779 System.Threading.Tasks.Task.RunContinuations(System.Object) [/_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs @ 3453]
0000004E5563F430 00007FFC06807A28 System.Threading.Tasks.Task.FinishSlow(Boolean) [/_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs @ 2009]
0000004E5563F490 00007FFC06808249 System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef, System.Threading.Thread) [/_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs @ 2359]
0000004E5563F530 00007FFC067F6EED System.Threading.ThreadPoolWorkQueue.Dispatch() [/_/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs @ 1099]
0000004E5563F5C0 00007FFC06803811 System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart() [/_/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs @ 128]
0000004E5563F8F0 00007ffc0faa69a3 [DebuggerU2MCatchHandlerFrame: 0000004e5563f8f0]

@Youssef1313
Copy link
Member

Youssef1313 commented Dec 27, 2024

I tried to do a bit of investigation here. I created a response file from binlog of the stuck build, and ran that with a locally built compiler for easier debugging. However, what I noticed is analyzer crash that makes sense.

Image

The analyzer is incorrectly authors and uses typeof(PropertyToReactiveFieldCodeFixProvider).FullName for the "Category" to passed to DiagnosticDescriptor constructor. This then attempts to load MS.CA.Workspaces which wouldn't be available to command-line builds.

The mystery here:

  1. Why is this happening only in .NET 9.0.100 (Note: I think it doesn't repro with RC2)
  2. Why does the analyzer crash show only when debugging with a locally built compiler?
  3. How was this ever working with previous .NET SDKs?

@jaredpar @CyrusNajmabadi Does that make any sense to you?

@jaredpar
Copy link
Member

jaredpar commented Jan 5, 2025

Why does the analyzer crash show only when debugging with a locally built compiler?

Did you build the compiler in Debug?

How was this ever working with previous .NET SDKs?

Can't really think of a way it could. Do you have a compiler log I could look at?

@Youssef1313
Copy link
Member

Did you build the compiler in Debug?

Yup. Is it expected to have this kind of behavior difference between Debug and Release builds of the compiler?

Can't really think of a way it could. Do you have a compiler log I could look at?

No, I can get one though.
But to repro, it was as simple as including the package ref in a console app (and ensure global.json has "allowPrerelease": false to ensure .NET 9 preview isn't picked up over .NET 9 stable. (The hang isn't reproducible with preview).

@jaredpar
Copy link
Member

jaredpar commented Jan 5, 2025

Yup. Is it expected to have this kind of behavior difference between Debug and Release builds of the compiler?

The underlying error is a TypeInitializationException which means it's triggered when the runtime decides to load that type. There are cases where type load timing can be different in debug / release cause it changes optimizations and hence when the runtime actually initializes a type. It's not that it's expected to change but it could explain it.

But to repro, it was as simple as including the package ref in a console app (and ensure global.json has "allowPrerelease": false to ensure .NET 9 preview isn't picked up over .NET 9 stable. (The hang isn't reproducible with preview).

Yes it's pretty easy to repro with 9.0.101. When I look at this under the debugger though it seems that it's the runtime that has locked up here. All the threads which are creating DiagnosticInfo instances are stuck in a native wait. No amount of waiting gets them unstuck. I assume this is waiting for the type system to load the type and that is failing with the TypeInitializationException. This doesn't seem to manifest though as an exception in the actual compiler.

@agocke, @davidwrighton any changes to type loading that could explain this behavior in the .NET 9 timeframe?

@agocke
Copy link
Member

agocke commented Jan 8, 2025

@mangod9 It looks like this has a reliable repro that can produce a dump, and is a regression from 9.0 preview. Could someone take a look?

@davidwrighton
Copy link
Member

@steveisok This should be looked at by someone on your team.

@kg
Copy link
Member

kg commented Jan 9, 2025

It looks like the hang is because while trying to acquire the cctor lock for ReactiveUI.SourceGenerators.Diagnostics.DiagnosticDescriptors, we try to acquire a critical section that is currently held by the main thread. It's not clear to me how this happened, because the main thread seems to be doing a synchronous GetResult on a Task:
Image

@kg
Copy link
Member

kg commented Jan 9, 2025

Before the deadlock, an exception is thrown on the main thread:

System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.CodeAnalysis.Workspaces, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.'

With the following stack:

0:000> !CLRStack
OS Thread Id: 0x1b74 (0)
        Child SP               IP Call Site
0000004D3F374960 00007ffd5bd30424 [InlinedCallFrame: 0000004d3f374960] 
0000004D3F374960 00007ffc644b7b26 [InlinedCallFrame: 0000004d3f374960] 
0000004D3F374900 00007ffc644b7b26 System.Runtime.EH.DispatchEx(System.Runtime.StackFrameIterator ByRef, ExInfo ByRef) [/_/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs @ 864]
0000004D3F374A60 00007ffc644b744d System.Runtime.EH.RhThrowEx(System.Object, ExInfo ByRef) [/_/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs @ 645]
0000004D3F37D318 00007ffc6b1c69a3 [PrestubMethodFrame: 0000004d3f37d318] ReactiveUI.SourceGenerators.Diagnostics.DiagnosticDescriptors..cctor()
0000004D3F37DC68 00007ffc6b1c69a3 [HelperMethodFrame: 0000004d3f37dc68] 
0000004D3F37DD90 00007ffc0c1801a4 ReactiveUI.SourceGenerators.AsyncVoidReturningReactiveCommandMethodAnalyzer..ctor() [c:\temp\releaser\ReactiveUI.SourceGenerators\src\ReactiveUI.SourceGenerators\Diagnostics\Analyzers\AsyncVoidReturningReactiveCommandMethodAnalyzer.cs @ 23]
0000004D3F37DDF0 00007ffc6436960c System.RuntimeType.CreateInstanceDefaultCtor(Boolean, Boolean) [/_/src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs @ 3922]
0000004D3F37DE60 00007ffc62fae54f Microsoft.CodeAnalysis.Diagnostics.AnalyzerFileReference+Extensions`1[[System.__Canon, System.Private.CoreLib]].GetAnalyzersForTypeNames(System.Reflection.Assembly, System.Collections.Immutable.ImmutableHashSet`1<System.String>, Boolean ByRef) [/_/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerFileReference.cs @ 626]
0000004D3F37DF00 00007ffc62fae3a9 Microsoft.CodeAnalysis.Diagnostics.AnalyzerFileReference+Extensions`1[[System.__Canon, System.Private.CoreLib]].GetLanguageSpecificAnalyzers(System.Reflection.Assembly, System.Collections.Immutable.ImmutableSortedDictionary`2<System.String,System.Collections.Immutable.ImmutableHashSet`1<System.String>>, System.String, Boolean ByRef) [/_/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerFileReference.cs @ 583]
0000004D3F37DF50 00007ffc62fae0bb Microsoft.CodeAnalysis.Diagnostics.AnalyzerFileReference+Extensions`1[[System.__Canon, System.Private.CoreLib]].AddExtensions(Builder<System.__Canon>, System.String, System.Func`2<System.__Canon,Boolean>) [/_/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerFileReference.cs @ 541]
0000004D3F37DFD0 00007ffc62dd4d63 Microsoft.CodeAnalysis.CommandLineArguments.ResolveAnalyzersFromArguments(System.String, System.Collections.Generic.List`1<Microsoft.CodeAnalysis.DiagnosticInfo>, Microsoft.CodeAnalysis.CommonMessageProvider, Microsoft.CodeAnalysis.IAnalyzerAssemblyLoader, Microsoft.CodeAnalysis.CompilationOptions, Boolean, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer> ByRef, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.ISourceGenerator> ByRef) [/_/src/Compilers/Core/Portable/CommandLine/CommandLineArguments.cs @ 550]
0000004D3F37E0A0 00007ffc50a604ae Microsoft.CodeAnalysis.CSharp.CSharpCompiler.ResolveAnalyzersFromArguments(System.Collections.Generic.List`1<Microsoft.CodeAnalysis.DiagnosticInfo>, Microsoft.CodeAnalysis.CommonMessageProvider, Microsoft.CodeAnalysis.CompilationOptions, Boolean, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer> ByRef, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.ISourceGenerator> ByRef) [/_/src/Compilers/CSharp/Portable/CommandLine/CSharpCompiler.cs @ 341]
0000004D3F37E120 00007ffc62ddafd8 Microsoft.CodeAnalysis.CommonCompiler.RunCore(System.IO.TextWriter, Microsoft.CodeAnalysis.ErrorLogger, System.Threading.CancellationToken) [/_/src/Compilers/Core/Portable/CommandLine/CommonCompiler.cs @ 941]
0000004D3F37E2D0 00007ffc62dda9bd Microsoft.CodeAnalysis.CommonCompiler.Run(System.IO.TextWriter, System.Threading.CancellationToken) [/_/src/Compilers/Core/Portable/CommandLine/CommonCompiler.cs @ 781]
0000004D3F37E340 00007ffcff258e27 Microsoft.CodeAnalysis.CSharp.CommandLine.Csc+c__DisplayClass1_0.b__0(System.IO.TextWriter) [/_/src/Compilers/Shared/Csc.cs @ 28]
0000004D3F37E370 00007ffcff25bc60 Microsoft.CodeAnalysis.CommandLine.ConsoleUtil.RunWithUtf8Output[[System.Int32, System.Private.CoreLib]](System.Func`2<System.IO.TextWriter,Int32>) [/_/src/Compilers/Core/CommandLine/ConsoleUtil.cs @ 26]
0000004D3F37E3C0 00007ffcff2555e1 Microsoft.CodeAnalysis.CSharp.CommandLine.Csc.Run(System.String[], Microsoft.CodeAnalysis.BuildPaths, System.IO.TextWriter, Microsoft.CodeAnalysis.IAnalyzerAssemblyLoader) [/_/src/Compilers/Shared/Csc.cs @ 28]
0000004D3F37E470 00007ffcff256ecc Microsoft.CodeAnalysis.CommandLine.BuildClient.RunCompilation(System.Collections.Generic.IEnumerable`1<System.String>, Microsoft.CodeAnalysis.BuildPaths, System.IO.TextWriter, System.String) [/_/src/Compilers/Shared/BuildClient.cs @ 167]
0000004D3F37E580 00007ffcff256c73 Microsoft.CodeAnalysis.CommandLine.BuildClient.Run(System.Collections.Generic.IEnumerable`1<System.String>, Microsoft.CodeAnalysis.CommandLine.RequestLanguage, Microsoft.CodeAnalysis.CommandLine.CompileFunc, Microsoft.CodeAnalysis.CommandLine.CompileOnServerFunc, Microsoft.CodeAnalysis.CommandLine.ICompilerServerLogger) [/_/src/Compilers/Shared/BuildClient.cs @ 116]
0000004D3F37E620 00007ffcff25574d Microsoft.CodeAnalysis.CSharp.CommandLine.Program.MainCore(System.String[]) [/_/src/Compilers/CSharp/csc/Program.cs @ 37]
0000004D3F37E6B0 00007ffcff255614 Microsoft.CodeAnalysis.CSharp.CommandLine.Program.Main(System.String[]) [/_/src/Compilers/CSharp/csc/Program.cs @ 18]

So my working theory is that this is leaving a lock held which causes us to deadlock later on.

@kg
Copy link
Member

kg commented Jan 9, 2025

The initial assembly load failure exception appears to happen during JIT compilation for the cctor. For some reason it seems like when we unwind this exception we're skipping straight over the rest of the logic for running the cctor without releasing the lock it's holding (?) which doesn't seem like it should be possible. When I "step out" in windbg it leaps really far up the stack, and the same is true if I try to step through exception handling in Visual Studio as well.

There are multiple exception handlers on the stack that intentionally suppress exceptions, which might be part of the problem? But it still doesn't make sense to me that we'd fail to release a lock we're holding inside the runtime. The use of an exception filter in the 2nd one caught my attention.

Image
Image

@kg
Copy link
Member

kg commented Jan 9, 2025

Thanks @davidwrighton for helping me determine that setting DOTNET_LegacyExceptionHandling=1 causes this not to deadlock. @janvorli do you want me to send you a time-travel debugging trace? the repro is quite simple so I can also just send you a folder with a .rsp to reproduce the issue.

EDIT: Here's a repro folder
roslyn-issue76531.zip

@kg kg assigned kg and janvorli Jan 9, 2025
@jaredpar
Copy link
Member

Well at least I think I understand what changed to explain why this is showing up in 9.0.100 but not before. Consider this change where I added the exception filter to this code path. That would've likely appeared first in 9.0.100.

Note: will use this situation as another plea to please provide AssemblyLoadContext.TryLoadFromAssemblyName. Having guaranteed exceptions on compiler startup is an endless source of problems for the team. Any debugging of the compiler starts with a series of F5 to skip past the guaranteed exceptions on startup. The more analyzers, the more exceptions. In this case the API would have saved us from this bug 😄

@janvorli
Copy link
Member

Let me take a look

@janvorli
Copy link
Member

I have found the culprit and have a fix. I will send out a PR after creating a simpler regression test for the issue.
Thank you @kg a lot for the repro, that helped me to discover the culprit and verify the fix.

@janvorli
Copy link
Member

It turns out Linux has the same problem. Also, I've found that the fix I have has a problem w.r.t. the inner exception (FileNotFoundException) having an empty stack trace. I need to figure out a good way to fix that too.

@Youssef1313
Copy link
Member

@jaredpar The linked runtime PR is merged. I think this can be closed

@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Feb 11, 2025
@jkotas
Copy link
Member

jkotas commented Feb 12, 2025

The fix was reverted in #112466

@jkotas jkotas reopened this Feb 12, 2025
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Feb 12, 2025
@jkotas jkotas transferred this issue from dotnet/roslyn Feb 12, 2025
@jkotas jkotas unassigned kg Feb 12, 2025
@jkotas jkotas added area-ExceptionHandling-coreclr and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Feb 12, 2025
@jkotas jkotas added this to the 10.0.0 milestone Feb 12, 2025
@janvorli
Copy link
Member

The fixed fix was merged in #112666

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants