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);
}
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.
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 callCreateRuntime()
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); }
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.