Repository navigation
Closed
Labels
bugSomething isn't working
Description
Our tools run the same logic as the dotnet-gcdump tool. It occasionally crashes on macOS (default GitHub Actions Runner image) with the stack trace below. Related code:
var heapInfo = new DotNetHeapInfo();
var memoryGraph = new MemoryGraph(50_000);
if (EventPipeDotNetHeapDumper.DumpFromEventPipe(cancellationToken, processId, null,
memoryGraph, logWriter, 30, heapInfo))
{
memoryGraph.AllowReading();
GCHeapDump.WriteMemoryGraph(memoryGraph, outputPath, "dotnet-gcdump");
return true;
}Stack trace of the crash:
0.5s: EventPipe Listener dying
0.5s: [Error] Exception during gcdump: System.AggregateException: One or more errors occurred. (Specified argument was out of the range of valid values.)
---> System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
at System.IO.StreamWriter.WriteFormatHelper(String format, ReadOnlySpan`1 args, Boolean appendNewLine)
at System.IO.StreamWriter.WriteLine(String format, Object arg0)
at Microsoft.Diagnostics.Tools.GCDump.EventPipeDotNetHeapDumper.<>c__DisplayClass3_1.<DumpFromEventPipe>b__5() in /_/src/Tools/dotnet-gcdump/DotNetHeapDump/EventPipeDotNetHeapDumper.cs:line 269
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.WaitAllCore(ReadOnlySpan`1 tasks, Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.WaitAll(Task[] tasks, Int32 millisecondsTimeout)
at Microsoft.Diagnostics.Tools.GCDump.EventPipeDotNetHeapDumper.DumpFromEventPipe(CancellationToken ct, Int32 processId, String diagnosticPort, MemoryGraph memoryGraph, TextWriter log, Int32 timeout, DotNetHeapInfo dotNetInfo) in /_/src/Tools/dotnet-gcdump/DotNetHeapDump/EventPipeDotNetHeapDumper.cs:line 274
[ 0.5s: Done Dumping .NET heap success=True]
---- System.ApplicationException : RootIndex not set.
This is nearly impossible to reproduce for us.
Full log at: https://github.com/SteeltoeOSS/Steeltoe/actions/runs/34455238672/job/102799980981.
Full source code at: https://github.com/SteeltoeOSS/Steeltoe/blob/main/src/Management/src/Endpoint/Actuators/HeapDump/HeapDumper.cs#L103
Any thoughts on what could be causing this, or where to look further?
Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Activity
hoyosjs commentedon Sep 19, 2026
Gcdump crash investigation
Conclusion
The reported failure is a race in
EventPipeDotNetHeapDumperlogging, followed by a false success result. It is not evidence of macOS GC heap corruption. A fix is needed in diagnostics, and Steeltoe can apply partial mitigations while waiting for a fixed package.DumpFromEventPipewrites to the caller-providedTextWriterfrom multiple threads. Steeltoe passes a plainStreamWriterover aMemoryStream, andStreamWriteris not thread-safe. During session shutdown, the EventPipe reader task and stop task finish at nearly the same time and both callWriteLineon that writer. The resulting corruption ofStreamWriterinternal buffer state produces the reportedArgumentOutOfRangeExceptionfromStreamWriter.Flush.The method then catches the exception but returns
truebecausedumpCompletewas set when the GC stop event was observed. The exception preventedConvertHeapDataToGraph()from running, so the graph still has no root. Steeltoe seestrue, callsmemoryGraph.AllowReading(), and getsRootIndex not set.Failure sequence
.NET GC Complete, and setsdumpComplete = trueinsrc/Tools/dotnet-gcdump/DotNetHeapDump/EventPipeDotNetHeapDumper.cs.dumpCompleteand startsstopTask.stopTasklogsShutting down gcdump EventPipe sessionand callsEndSession().Found Modulemessages throughDotNetHeapDumpGraphReaderwhilestopTaskproceeds afterEndSession().stopTasklogsgcdump EventPipe session shut downat line 269 while the reader thread is writing a rundown module message.TextWriter. In Steeltoe this is an unsynchronizedStreamWritercreated byCaptureLogOutput.gcdump EventPipeQuic.dll ID ...combines text fromgcdump EventPipe session shut downandFound Module System.Net.Quic.dll ID .... The line 269 write then throws fromStreamWriter.Flush.Task.WaitAllsurfaces the task exception asAggregateException. The outer catch logs it and continues.dumper.ConvertHeapDataToGraph(), which builds the graph root and assignsm_graph.RootIndexinDotNetHeapDumpGraphReader.cs.DumpFromEventPipereturns the already-truedumpComplete. Steeltoe callsAllowReading(), andGraph.AllowReading()throws becauseRootIndexis still invalid.The timestamps from the failing job reinforce the race:
There are many
Found Modulemessages immediately before shutdown. This leaves theStreamWriterbuffer active and makes a concurrent write or flush more likely to expose the race.Why this affects the Steeltoe integration
The original dotnet-gcdump CLI passes either
Console.OutorTextWriter.Null.Console.Outis synchronized by the runtime, andTextWriter.Nullhas no mutable stream buffer. During review of the original dotnet-gcdump pull request, the thread-safety risk was explicitly raised. The response was that the CLI writers were already safe.That assumption does not hold when another component directly references the tool assembly and passes a plain
StreamWriter, as Steeltoe does withdotnet-gcdump9.0.652701. The assembly is packaged as a tool rather than as a supported library API, so Steeltoe's direct assembly reference is an unsupported consumption pattern. However, diagnostics still needs a fix because the false-success behavior also affects the shipped CLI whenever any exception occurs after the GC stop event but before graph conversion completes.The failed Steeltoe workflow attempt failed only for the net10.0 gcdump case on macOS. The same unchanged commit passed on rerun. That is consistent with a scheduling-sensitive race rather than deterministic graph corruption.
Additional defect: process-wide completion state
eventPipeDataPresentanddumpCompletearestatic volatilefields. They are never reset at the start of eitherDumpFromEventPipeorDumpFromEventPipeFile.This creates a separate reentrancy problem:
dumpComplete = truefor every later collection in the process.eventPipeDataPresentcan also remain true, causing conversion to be attempted with partial or unrelated event data.This static-state issue is not required to explain the specific first-call Steeltoe failure, because the current GC stop event set
dumpCompletebefore shutdown. It can, however, cause additional intermittent failures for a long-lived endpoint that collects more than one gcdump.Diagnostics fix
The diagnostics change:
GCStopand returnstrueonly afterConvertHeapDataToGraph()completes.The regression coverage uses the real self-gcdump path to verify that an exception during shutdown logging returns
false.Caller-side mitigation
Steeltoe must provide a writer that supports concurrent writes when it calls
DumpFromEventPipedirectly. It can use a synchronized writer:Until Steeltoe consumes a diagnostics build with the false-success fix, it should check
memoryGraph.RootIndex != NodeIndex.Invalidbefore callingAllowReading().Verification
The initial diagnosis was independently confirmed with Claude Opus 5 by review of the complete failing job log, the exact Steeltoe source and dependency versions at the failing commit, the consumed
v9.0.652701diagnostics source, current diagnostics source, the original dotnet-gcdump pull request discussion, and the .NETStreamWriterimplementation.A local regression repro was then run against the unmodified production implementation. The real self-gcdump test failed with:
After the narrowed fix, the targeted test passes in Debug and Release. The complete test outputs were preserved as session artifacts.
Relevant references:
src/Tools/dotnet-gcdump/DotNetHeapDump/EventPipeDotNetHeapDumper.cssrc/Tools/dotnet-gcdump/DotNetHeapDump/DotNetHeapDumpGraphReader.cssrc/Tools/dotnet-gcdump/DotNetHeapDump/Graph.cs102799980981, successful rerun job102807684637dotnet/runtimeStreamWriter.Flush,StreamWriter.WriteFormatHelper, andTextWriter.Synchronizedhoyosjs commentedon Sep 19, 2026
@bart-vmware - I had looked a bit at this and say a few issues. I set and agent and it got to even reply before I did. The answer is pretty thorough. Essentially there's 3 issues:
bart-vmware commentedon Sep 21, 2026
@hoyosjs Thanks for the analysis, this is immensely helpful! In Steeltoe, we can:
NodeIndex.InvalidTextWriterI did some benchmarking on alternatives for
TextWriter.Synchronized; will add a suggestion in #6051.Implement countermeasures described in dotnet/diagnostics#6048
Update memory dump dependencies (#1744)
Fix gcdump false success after collection errors (dotnet#6051)
Fix gcdump false success after collection errors (#6051)