Repository navigation
Fix gcdump false success after collection errors - #6051
Conversation
Co-authored-by: Copilot App <[email protected]> Copilot-Session: 432587bf-ff0a-4257-ad8a-fc58a1a8c6a9
Serialize writes to caller-provided output writers, keep completion state local to each collection, and report success only after graph conversion finishes. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 432587bf-ff0a-4257-ad8a-fc58a1a8c6a9
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The test project is missing an xUnit package reference and cannot compile the tests.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
Fixes an occasional gcdump crash caused by concurrent logging and stale completion state.
Changes:
- Serializes
TextWriteraccess. - Uses per-invocation completion state.
- Adds self-gcdump regression tests.
| File | Summary |
|---|---|
src/Tools/dotnet-gcdump/DotNetHeapDump/EventPipeDotNetHeapDumper.cs |
Fixes logging races and completion-state handling. |
src/tests/dotnet-gcdump/EventPipeDotNetHeapDumperTests.cs |
Adds regression coverage. |
src/tests/dotnet-gcdump/DotnetGCDump.UnitTests.csproj |
Adds the gcdump test project. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Require the concurrency test to observe both shutdown and rundown logging, and make shutdown fault injection independent of TextWriter overload forwarding. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 432587bf-ff0a-4257-ad8a-fc58a1a8c6a9
|
@steveisok, @lateralusX, @max-charlamb Any thoughts on the performance impact of the |
Require callers to provide a writer that supports concurrent writes, retain resettable static collection state, and keep success gated on completed graph conversion. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 432587bf-ff0a-4257-ad8a-fc58a1a8c6a9
|
I'm still trying to decide if this change makes sense to take with the synchronized textwriter. As pointed out in #5508 (comment) - gcdump is not an API, but rather a tool. Pushing the things to statics does help with testability and the error handling part too. If steeltoe decides to use that textwriter implementation, all will work. However - as we move towards tools being vertical RID-specific packages and then potentially AOTd, then this way of consuming it will for sure break. |
Expose dotnet-gcdump internals to its unit tests and seed the retained static completion fields so both entry points deterministically verify their reset behavior. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 432587bf-ff0a-4257-ad8a-fc58a1a8c6a9
Ensure the false-success regression test reaches the simulated shutdown logging exception instead of passing on an unrelated EventPipe setup failure. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 432587bf-ff0a-4257-ad8a-fc58a1a8c6a9
Thanks for sharing your concerns. What Steeltoe offers is feature parity with the Java Spring Boot Heap Dump Actuator for .NET apps. Spring Boot Actuators are consumed by UIs such as the Apps Manager for Elastic Application Runtime, Spring Boot Admin and Ostara. Such tools provide unified operational management for polyglot enterprise apps. Steeltoe later added the GC-dump type, to make it easier to analyze dumps cross-platform (Windows/Linux/macOS). I'm well aware that Steeltoe uses the code/package from this repository in a way it was never designed for. And any support for making our lives easier should not be interpreted as a precedent that libraries are supported. On the other hand, we are actively testing the code and report back issues, so I hope there's some value in that for the team? Like I said, Steeltoe can take care of the Long term, do you have any suggestions for how we could take .NET heap/gc/thread dumps via other APIs? We don't have the deep runtime knowledge you guys do, so any ideas are appreciated. |
Keep EventPipe collection completion state isolated to each live or file conversion operation while retaining the post-conversion success check. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 432587bf-ff0a-4257-ad8a-fc58a1a8c6a9
|
@bart-vmware I am not saying by any means that this is not something valuable - or that the changes I suggested are not gonna make it in. The static state and the conversion error fixes are now in this PR and I think this is what makes sense to take in. I see your PR adds the proposed TextWriter with a Lock - so this and that should be sufficient. As for the APIs - we'd probably need to design whatever needs to happen and ship it as a library instead of a tool. We'd just prioritize that just as we prioritize other work. For now, I hope that this at least unblocks y'all's use cases. |
|
@hoyosjs Thanks, LGTM. This means we can remove the check for |
Fixes #6048 ## Summary - Keep EventPipe completion state local to each live collection and file conversion. - Report success only after heap graph conversion completes. - Document that the live collection log writer must support concurrent writes. - Add regression coverage for a post-GCStop logging failure returning false. ## Root cause The failure in #6048 has two parts. Steeltoe calls `EventPipeDotNetHeapDumper` directly and supplies a plain `StreamWriter`, while the method logs concurrently from the EventPipe reader and session stop tasks. That caller-provided writer is not thread-safe, which explains the torn log line and `StreamWriter.Flush` exception. The shipped CLI uses synchronized `Console.Out`, so diagnostics continues to require callers of the direct API to provide a writer that supports concurrent writes. After the logging exception, graph conversion is skipped. The previous implementation nevertheless returned the process-wide `dumpComplete` flag set when `GCStop` was observed. The caller therefore received `true` for an unconverted graph and failed with `RootIndex not set`. The process-wide flags also allowed separate or concurrent operations to affect each other. This change gives each operation its own completion state and separates GC completion from operation success. `true` is returned only after `ConvertHeapDataToGraph()` completes. Steeltoe must separately use a synchronized writer for direct in-process gcdump calls. ## Reproduction A real self-gcdump test injects a logging failure after `GCStop` and verifies that the operation returns `false` because graph conversion did not complete. The targeted test passes in Debug and Release. --------- Copilot-Session: 432587bf-ff0a-4257-ad8a-fc58a1a8c6a9 (cherry picked from commit 2a16a62) Co-authored-by: Copilot App <[email protected]> Copilot-Session: 1bf039ff-37e1-40b6-af8c-125192e61855
#6078) Backport the Linux `/proc` process-discovery fix for #6040 and the gcdump and dotnet-trace changes needed on `release/stable`: - #5886: non-lossy EventPipe buffering for gcdump and `dotnet-trace collect --buffering-mode Block`. - #6051: report gcdump success only after heap conversion completes. - #5970: remove the `collect-linux` preview banner. - #6071: update `record-trace` and add `collect-linux --max-memory`. Non-lossy buffering requires a .NET 11+ target runtime; gcdump warns and falls back to lossy collection for older runtimes. Linux-specific behavior has not been exercised locally on Windows.

Fixes #6048
Summary
Root cause
The failure in #6048 has two parts. Steeltoe calls
EventPipeDotNetHeapDumperdirectly and supplies a plainStreamWriter, while the method logs concurrently from the EventPipe reader and session stop tasks. That caller-provided writer is not thread-safe, which explains the torn log line andStreamWriter.Flushexception. The shipped CLI uses synchronizedConsole.Out, so diagnostics continues to require callers of the direct API to provide a writer that supports concurrent writes.After the logging exception, graph conversion is skipped. The previous implementation nevertheless returned the process-wide
dumpCompleteflag set whenGCStopwas observed. The caller therefore receivedtruefor an unconverted graph and failed withRootIndex not set. The process-wide flags also allowed separate or concurrent operations to affect each other.This change gives each operation its own completion state and separates GC completion from operation success.
trueis returned only afterConvertHeapDataToGraph()completes.Steeltoe must separately use a synchronized writer for direct in-process gcdump calls.
Reproduction
A real self-gcdump test injects a logging failure after
GCStopand verifies that the operation returnsfalsebecause graph conversion did not complete. The targeted test passes in Debug and Release.