You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using CreateSnapshotAndAttach to get stack dumps for all threads, calling it on my own process. Despite calling dispose on the DataTarget and ClrRuntime objects a process is left behind.
A small sample program shows the problem:
using System;
using System.Linq;
using Microsoft.Diagnostics.Runtime;
namespace ClrMDTest
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Press any key to stack dump all threads.");
Console.ReadLine();
PrintStackDump();
Console.WriteLine("Stack dump complete... press any key to exit.");
Console.ReadLine();
Console.WriteLine("Exiting...");
}
private static void PrintStackDump()
{
Console.WriteLine("Attempt to stack dump threads:");
DataTarget target = null;
ClrRuntime runtime = null;
try
{
target = DataTarget.CreateSnapshotAndAttach(Environment.ProcessId);
runtime = target.ClrVersions.First().CreateRuntime();
foreach (ClrThread thread in runtime.Threads)
{
Console.WriteLine($"ID:{thread.ManagedThreadId} OSID:{thread.OSThreadId} Alive:{thread.IsAlive} Finalizer:{thread.IsFinalizer} GC:{thread.IsGc}");
var stackFrames = thread.EnumerateStackTrace();
foreach (var clrStackFrame in stackFrames)
{
if (clrStackFrame.Method != null)
{
Console.WriteLine(" " + clrStackFrame.Method?.Signature);
}
}
Console.WriteLine();
}
}
catch (Exception ex)
{
Console.WriteLine($"Failed with exception: {ex}");
}
finally
{
runtime?.Dispose();
target?.Dispose();
}
}
}
}
This is likely a problem with the diagnostics IPC channel, owned by the dotnet/diagnostics repo as my usage of it hasn't changed in many versions. If so, I will transfer this to their repo. I'll take a look next week.
I'm using CreateSnapshotAndAttach to get stack dumps for all threads, calling it on my own process. Despite calling dispose on the DataTarget and ClrRuntime objects a process is left behind.
A small sample program shows the problem:
I'm using the latest version or ClrMD and .NET 8:
And publishing for Linux arm64:
Cross compiling on Windows for arm64 Linux using VS2022 17.8.1.
Running the program:
I check the process list:
Then press any key (I chose space, in case you were wondering):
Now the process list again:
A new process with the same name has showed up. Press space again:
And check the process list one more time:
Is there something I'm missing here? I checked the /tmp directory and the file tmpw9ZIYK.tmp was not there so must have been cleaned up successfully.
The text was updated successfully, but these errors were encountered: