Skip to content

EventPipeEventSource blocks until the first event is read #1060

Closed

Description

@davmason

If you follow the sample code on how to use EventPipeEventSource but replace the provider with a provider that doesn't produce any events, it will block forever in the constructor to EventPipeEventSource.

    var providers = new List<EventPipeProvider>()
    {
        new EventPipeProvider("Microsoft-Windows-DotNETRuntime",
            EventLevel.Informational, (long)ClrTraceEventParser.Keywords.GC)
    };

    var client = new DiagnosticsClient(processId);
    using (var session = client.StartEventPipeSession(providers, false))
    {
        var source = new EventPipeEventSource(session.EventStream);

        source.Clr.All += (TraceEvent obj) => {
            Console.WriteLine(obj.EventName);
        }
        try
        {
            source.Process();
        }
        // NOTE: This exception does not currently exist. It is something that needs to be added to TraceEvent.
        catch (EventStreamException e)
        {
            Console.WriteLine("Error encountered while processing events");
            Console.WriteLine(e.ToString());
        }
    }

It will block on this line: https://github.com/microsoft/perfview/blob/cb1943b8ded584e136e140746e5771ca63668c5a/src/TraceEvent/EventPipe/EventPipeEventSource.cs#L68

This seems like a pitfall, and it's not clear what is happening. I've used that code pattern lots before and it's never failed, then all of a sudden it hangs my app and I have to do a lot of digging to understand why. I imagine customers will run in to it as well.

Activity

  1. davmason commented on Apr 23, 2020

    @davmason
    ContributorAuthor
  2. Wojmik commented on May 12, 2020

    @Wojmik

    I have the same issue. Even in first sample code: https://github.com/dotnet/diagnostics/blob/master/documentation/design-docs/diagnostics-client-library.md
    If you debug line by line, it can be saw that it hangs for a while on EventPipeEventSource constructor.
    In the real application it is very hard even to Dispose, because constructor hangs, so you don't have reference to Dispose on.

  3. sywhang commented on May 12, 2020

    @sywhang
    Contributor

    @davmason I think a better place for this issue is the perfview repo since that's where TraceEvent and the implementation of EventPipeEventSource lives. For some reason it seems like I can't transfer this issue to PerfView repo so I just filed microsoft/perfview#1172 to track it there.

  4. ghost locked as resolved and limited conversation to collaborators on Jun 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions