Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EventPipeEventSource blocks until the first event is read #1060

Closed
davmason opened this issue Apr 23, 2020 · 3 comments
Closed

EventPipeEventSource blocks until the first event is read #1060

davmason opened this issue Apr 23, 2020 · 3 comments

Comments

@davmason
Copy link
Member

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.

@davmason
Copy link
Member Author

cc @sywhang

@Wojmik
Copy link

Wojmik commented May 12, 2020

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.

@sywhang
Copy link
Contributor

sywhang commented May 12, 2020

@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.

@sywhang sywhang closed this as completed May 12, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jun 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants