microsoft / clrmd

Microsoft.Diagnostics.Runtime is a set of APIs for introspecting processes and dumps.
MIT License
1.05k stars 254 forks source link

CLR crashes soon after CreateRuntime called on Linux #1282

Open iskiselev opened 3 weeks ago

iskiselev commented 3 weeks ago

On linux, after attempt to CreateSnapshotAndAttach for it's own process CLR crashes soon after the thread that called CreateRuntime() finishes. Looks like it happens when some resources disposed, so it may work some not-long time. To reproduce it is enough to call CreateRuntime() in separate thread and wait a little bit after thread will be finished. Repro steps:

var t = new Thread(() => { try { using var dataTarget = DataTarget.CreateSnapshotAndAttach(Process.GetCurrentProcess().Id); using var runtime = dataTarget.ClrVersions[0].CreateRuntime(); } catch (Exception e) { Console.WriteLine(e); } }); t.Start(); t.Join();

Console.WriteLine("Done Get Runtime!");

while (true) { Console.WriteLine("!!!!!!!! " + DateTime.Now); Thread.Sleep(1000); }

- project
```xml
<Project Sdk="Microsoft.NET.Sdk">

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

  <ItemGroup>
    <PackageReference Include="Microsoft.Diagnostics.NETCore.Client" Version="0.2.532401" />
    <PackageReference Include="Microsoft.Diagnostics.Runtime" Version="4.0.0-beta.24360.3" />
  </ItemGroup>

</Project>

I've reproduced issue with different versions of Microsoft.Diagnostics.Runtime/Microsoft.Diagnostics.NETCore.Client and DOTNET runtime.