1

When trying to compile a call to HtmlHelper.Partial in an ASP.NET Core MVC application, I get the following warning:

warning MVC1000: Use of IHtmlHelper.Partial may result in application deadlocks. Consider using Tag Helper or IHtmlHelper.PartialAsync.

There is lots of advice online that suggests following this warning. What I am looking for is to understand the root cause of this so that I can see if other coding patterns not using HtmlHelper.Partial might lead to similar issues.

The only explanation I've found so far is in this locked thread, which says that it has to do with taking up "task slots" but does not go into detail.

I can imagine a deadlock case where EVERY threadpool thread was blocked synchronously waiting on some Task and none of those tasks could complete because they were waiting to be scheduled on the threadpool threads AND the threadpool is at max threads and won't allocate more, but this seems like something that could happen with any sync-over-async code and feels somewhat unlikely with a high max thread count, so I'm guessing that there is something more to it.

Note: Tag Helper vs HTML Helper "Use of IHtmlHelper.Partial may result in application deadlocks" mentions this but is more focused on TagHelpers (as is the response)

ChaseMedallion
  • 20,860
  • 17
  • 88
  • 152
  • The max `ThreadPool` worker-thread count on a machine I'm using is 32k. As the OP suggests in the issue linked, if I'm running an ASP.NET Core application that renders a partial using sync-over-async in the layout page, I'd only need to have more than 32k active requests to see the issue, which is just thread pool starvation. – Kirk Larkin Jun 07 '19 at 16:03
  • @KirkLarkin so you're saying that this would be an issue with any sync-over-async code under high enough load; there's nothing specific about either ASP.NET Core (vs. legacy ASP.NET) or HtmlHelper.Partial? – ChaseMedallion Jun 07 '19 at 17:12
  • Correct, that's how I understand it. The problem boils down to the synchronous use of `GetAwaiter().GetResult()`, which isn't specific to either of the things you mentioned. I don't think you need to worry about the same problem occurring elsewhere in ASP.NET Core, so long as you're not using sync-over-async yourself. From what I can see on the linked thread (and its linked threads, etc), this is very specific to `HtmlHelper`. – Kirk Larkin Jun 07 '19 at 17:18

0 Answers0