High CPU Hang in v2.0.2


#1

I just wanted to bring this to people’s attention because it has been biting us in our production environment. The latest version, 2.0.2, currently available via NuGet has a serious race condition bug that can cause a high CPU hang whether the profiler is enabled or not. It will affect you if you are including the rendering code in your views as documented on the home page:

<body>
...
@MiniProfiler.RenderIncludes()
</body>

This call ultimately makes a call to look up a value in a static dictionary collection which is not thread safe and runs into the issue seen in this blog post. Here is the problem code disassembled from .NET Reflector:

        internal static HtmlString RenderIncludes(MiniProfiler profiler, RenderPosition? position = new RenderPosition?(), bool? showTrivial = new bool?(), bool? showTimeWithChildren = new bool?(), int? maxTracesToShow = new int?(), bool? showControls = new bool?(), bool? useExistingjQuery = new bool?())
        {
            string format = GetResource("include.partial.html");
            string result = "";
            if (profiler != null)
            {
               ...
            }
            return new HtmlString(result);
        }

    private static readonly Dictionary<string, string> _ResourceCache;

    private static string GetResource(string filename)
    {
        string result;
        filename = filename.ToLower();
        if (!_ResourceCache.TryGetValue(filename, out result))
        {
            ...
        }
        return result;
    }

I see in github the issue has already been addressed by changing to a ConcurrentDictionary but this is not included in the current NuGet package.

Hope this helps someone else out.


#2

I have also seen the same problem: Miniprofiler 2.02 hanged with full CPU core usage in HtmlString.RenderIncludes(). Fortunately I excluded the RenderIncludes statement from execution on our production server, but this does seem to a be a serious issues.

Are there any plans to fix this issue?