ASP.NET Hang - Generic Dictionary concurrency issues causes GC deadlock

给你一囗甜甜゛ 提交于 2019-11-30 06:29:35

So we eventually got to the bottom of the problem. It turned out to be a combination of the two articles mentioned in my original question:

  • There are two threads trying to access the same generic Dictionary
  • The GC cannot complete because the two threads have PreEmptive GC set to disabled.

In a bit more detail:

Whilst the two threads are in some sort of deadlock, a third thread joins the party wanting to allocate some memory on the heap. This triggers a new GC, but the GC cannot complete because these two threads have their PreEmptive GC set to disabled. Because the GC cannot complete, the IIS process remains in a state where no new worker threads can be spawned for requests, meaning that any subsequent requests are queued. The queues continues to grow, and no responses are returned until the app pool is recycled.

As I mentioned in my original question - we traced the dictionary back to code and it WASN'T a static dictionary, so we assumed this must be a red herring; how else could two threads gain access to the same object? Well it turns out this was made possible because the dictionary was stored in an InProc session.

ASP.NET by default prevents concurrent requests for the same session ID. This is achieved by putting an exclusive lock on the session per request and designed to prevent this exact scenario. However, this is a 'legacy' app that uses the old AjaxPro framework and had been configured to bypass this locking. This allowed concurrent AjaxRequests for the same session to access the same session object.

It turned out that we had recently introduced a bug in our JavaScript that fired off the same AjaxPro request multiple times thus causing the issue.

This may be entirely out of left-field, but amid the dump info, I noticed this:

1c93eeac 79208c9b 67935cc0 6726b530 0ac4ea6c clr!COMToCLRDispatchHelper+0x28

That COMToCLRDispatchHelper call makes me wonder if the app is calling a 32-bit COM component that may be muddying the waters a bit for you?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!