4

The full exception text is:

EventSourceException: No Free Buffers available from the operating system (e.g. event rate too fast).

I am calling this method approx a million times because of recursion. It does not stop, I just get the exception text in the Output Debug windown in VS2013. But it is super slow.

private static IEnumerable<string> RecursiveFindServices(ISymbol sym, Solution sln)
{
    List<string> list = new List<string>();
    var callers = SymbolFinder.FindCallersAsync(sym, sln).Result;  // this line may cause the EventSourceException  (try not to call Async)
    foreach(var caller in callers)
    {
        string name = GetMethodName(caller);
        if (caller.CallingSymbol.ContainingType.Name.EndsWith("Test"))
            continue;

        if (recursiveList.Contains(name))
            continue;

        recursiveList.Add(name);

        if (IsWebservice(caller))
            list.Add(name);
        else
            list.AddRange(RecursiveFindServices(caller.CallingSymbol, sln));
    }

    return list;
}

Does anyone know what this exception means and how to fix it. I am assuming that the slow speed is related to this exception.

IsWebservice() and GetMethodName() are pure string methods.

I am running Roslyn in a VS2013 project under .NET 4.5.2, can it be related to this? I just installed this nuget package

PM> Install-Package Microsoft.CodeAnalysis

And then I had to copy over and include the following files in my project.

Microsoft.Build.Conversion.Core.dll     (File Version 14.0)
Microsoft.Build.dll                     (File Version 14.0)
Microsoft.Build.Engine.dll              (File Version 14.0)
Microsoft.Build.Framework.dll           (File Version 14.0)
Microsoft.Build.Tasks.Core.dll          (File Version 14.0)
Microsoft.Build.Utilities.Core.dll      (File Version 14.0)
System.Threading.Tasks.Dataflow.dll     (File Version 4.5.24)

Any ide how to speed up the code or find the root cause of the exception will be helpfull. //Thanks :-)

Julien Roncaglia
  • 17,397
  • 4
  • 57
  • 75
thomas nn
  • 933
  • 3
  • 13
  • 21
  • 1
    You said you call it a million times. How often do you call it, 1M times per second, or a million times as fast as possible then done... etc – MikeS159 Jul 23 '15 at 07:53
  • The exception is an *EventSourceException* - Your code is sending trace events to a source at too high a rate. Where does this exception occur? What is its call stack? Where do you log events? – Panagiotis Kanavos Jul 23 '15 at 09:23
  • 2
    BTW why are you blocking by calling `.Result` instead of using `async/await`? You are simply wasting CPU cycles this way. – Panagiotis Kanavos Jul 23 '15 at 09:25
  • @Mike159, I call it 1 million times as fast as I can. :-) – thomas nn Jul 23 '15 at 10:32
  • @PanagiotisKanavos: Thanks! I have started using await. ... and I also tried to enable break on all CLR Exceptions in VS2013, but then it just crash the whole VS2013. :-( – thomas nn Jul 23 '15 at 10:35
  • Did await work? I was going to suggest slowing down your calls deliberately (temporarily) to check if it was a slow garbage collection cleanup or something more problematic. – MikeS159 Jul 23 '15 at 11:29
  • @Mike159: No the await did not solve neither speed nor Exception. But inserting a Thread.Sleep(50) in the loop doubled the speed, because the Exception was significantly reduced. Now I guess I have to optimize the 50 ms sleep value by hand. – thomas nn Jul 24 '15 at 07:55
  • @thomasnn Interesting. It could well be something to do with garbage collection not releasing resources fast enough. Let me know what value works best in the end. – MikeS159 Jul 24 '15 at 08:17
  • Since you don't provide the exception details, I'll simply guess this is raised by Roslyn itself. Which raises the question - *why are you doing 1M calls at all*? The resulting code will be hideously slow and essentially unusable. It's like trying to query a 1M row table one row at a time. Create a graph instead where each symbol will appear only once and not queried if it's already present – Panagiotis Kanavos Jul 24 '15 at 11:22
  • Or just cache the visited symbols (eg in a HashSet<>, Dictionary<>, whatever) so that you *don't* reprocess already visited symbols – Panagiotis Kanavos Jul 24 '15 at 11:24
  • @PanagiotisKanavos: I just started using Roslyn and I am still eager to learn. Is there a way to create the entire reverse calling graph from any symbol? I end up with 1M calls, because it is a large project (20000 files) where we have a central enum with 2000 error codes. For each method in the service layer, I need to find out which error codes it can return. – thomas nn Jul 24 '15 at 12:29

2 Answers2

2

I run into this problem as well as I was developing a rendering method with VS 2013. I found a solution for stop spamming the console window with the message:

Go to the VS 2013 option menu:

In German this is:

EXTRAS --> Optionen… --> Debugging --> Allgemein --> (mark) Verwalteten Kmpatibilitäsmodus verwenden

In English this is:

TOOLS --> Options… --> Debugging --> General --> (mark) Use Managed Compatibility Mode

This will stop the message.

Jens Bornschein
  • 163
  • 2
  • 11
  • By the way, if you know how to reproduce this problem, could you add it to https://connect.microsoft.com/VisualStudio/feedbackdetail/view/2667405/eventsourceexception-exception-floods-debugging-session-and-slows-down-process? – johnildergleidisson May 25 '16 at 17:43
  • VS 2017 gives you a prompt telling you that Edit and Continue is disabled if you have this enabled. – Jason Stevenson May 12 '17 at 00:44
1

Have faced this exception too! Not sure if related or not my C: drive was full at that time, after freeing up some space, haven't got this exception.

Orion_Eagle
  • 124
  • 5