microsoft/clrmd

CLR crashes soon after CreateRuntime called on Linux

Opened this issue · 0 comments

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:

  • sources
using System.Diagnostics;
using Microsoft.Diagnostics.Runtime;

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
<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>
  • docker command to test (with docker running linux containers): docker run --rm --cap-add SYS_PTRACE -v %CD%:/app -w /app mcr.microsoft.com/dotnet/sdk:8.0 dotnet run

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