# High CPU Hang in v2.0.2

**URL:** <https://community.miniprofiler.com/t/high-cpu-hang-in-v2-0-2/33>\
**Category:** uncategorized\
**Created:** [February 2, 2013, 1:16pm UTC](https://community.miniprofiler.com/t/high-cpu-hang-in-v2-0-2/33 "2013-02-02T13:16:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Unknown39](https://avatars.discourse-cdn.com/v4/letter/u/dfb087/32.png) [@Unknown39](https://community.miniprofiler.com/u/Unknown39)\
**Post date:** [February 2, 2013, 1:16pm UTC](https://community.miniprofiler.com/t/high-cpu-hang-in-v2-0-2/33/1 "2013-02-02T13:16:41Z")

</div>

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](http://blogs.msdn.com/b/tess/archive/2009/12/21/high-cpu-in-net-app-using-a-static-generic-dictionary.aspx). 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](https://github.com/SamSaffron/MiniProfiler/commit/413f7005dfb6c2041eaec08a7732b9a36c6c0548) 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.

---

<div class="post-metadata">

**Author:** ![Adrian](https://sea2.discourse-cdn.com/flex016/user_avatar/community.miniprofiler.com/adrian/32/1005_2.png) [@Adrian](https://community.miniprofiler.com/u/Adrian)\
**Post date:** [February 21, 2013, 10:01pm UTC](https://community.miniprofiler.com/t/high-cpu-hang-in-v2-0-2/33/2 "2013-02-21T22:01:08Z")

</div>

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?
