Skip to content

dotnet-trace: unhandled exception results in a broken trace #2954

@CarnaViire

Description

@CarnaViire

Description

Unhandled exception in a program results in a broken trace collected by dotnet-trace. (If I catch the exception, the produced trace is OK)

Steps to reproduce:

  1. Run a program via dotnet run -c release
  2. Start collecting the trace via dotnet-trace collect -p <PID>
  3. At some point the program throws an unhandled exception and exits
  4. dotnet-trace exits too, says Trace completed. and produces a trace file

However, that trace file would be broken.

When trying to open it in PerfView, the error is

[ERROR: processing events ****]
***** Consider using /ContinueOnError to ignore the bad part of the trace.  *****
Error: Exception EventPipe conversion: System.Exception: Read past end of stream.
   at FastSerialization.IOStreamStreamReader.Fill(Int32 minimum)
   at FastSerialization.MemoryStreamReader.ReadByte()
   at FastSerialization.Deserializer.ReadObject()
   at Microsoft.Diagnostics.Tracing.EventPipeEventSource.Process()
   at Microsoft.Diagnostics.Tracing.Etlx.TraceLog.CopyRawEvents(TraceEventDispatcher rawEvents, IStreamWriter writer)
   at Microsoft.Diagnostics.Tracing.Etlx.TraceLog.<>c__DisplayClass120_0.<FastSerialization.IFastSerializable.ToStream>b__0()
   at FastSerialization.DeferedRegion.Write(Serializer serializer, Action toStream)
   at Microsoft.Diagnostics.Tracing.Etlx.TraceLog.FastSerialization.IFastSerializable.ToStream(Serializer serializer)
   at FastSerialization.Serializer.WriteObjectData(IFastSerializable obj, Tags beginTag)
   at FastSerialization.Serializer.WriteObjectRef(IFastSerializable obj, Boolean defered)
   at FastSerialization.Serializer..ctor(IStreamWriter writer, IFastSerializable entryObject)
   at Microsoft.Diagnostics.Tracing.Etlx.TraceLog.CreateFromEventPipeEventSources(TraceEventDispatcher source, String etlxFilePath, TraceLogOptions options)
   at Microsoft.Diagnostics.Tracing.Etlx.TraceLog.CreateFromEventPipeDataFile(String filePath, String etlxFilePath, TraceLogOptions options)
   at PerfView.EventPipePerfViewData.GetTraceLog(TextWriter log, Action`3 onLostEvents)
[Error: exception while opening EventPipe data.]

When trying to convert it to Speedscope format, via dotnet-trace convert, it would say

Detected a potentially broken trace. Continuing with best-efforts to convert the trace, but resulting speedscope file may contain broken stacks as a result.

and produce an empty result.

Configuration

OS: Windows 11
dotnet-trace version: 6.0.257301+27172ce4d05e8a3b0ffdefd65f073d40a1b1fe54
.NET SDK version: 7.0 Preview 2
App's target framework: net6.0 (.NET 6.0.2)

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions