1

Ever since I started working an MVC project with ASYNC from start - all controllers, database calls, etc. are async and awaited I have been in debug hell. I never get helpful debug/exception information - it's lost in the bowels of the system. I have to go into ELMAH or AI to view the exception since it never bubbles up and ends the request.

In most cases, the page will just spin away until the browser gives up. Am I missing something somewhere? For instance, I have an error on the page (null reference), but since the page is async, I never see the exception.

Unlike most of the questions asked here that tend to cause a deadlock, there is no use of .Result anywhere in this codebase. This is async form the start and all the way through.

To clarify, here is the exact workflow of this MVC controller. I made a few changes to test when it hangs and when it doesn't.

Controller

public async Task<ActionResult> Review(Guid id)
{
    var quote = await Quotes.GetQuoteById(id);
    return View();
}

Service

return await Ef.DbSet.Where(d => d.Id == id).FirstOrDefaultAsync();

View (first line)

@{ throw new ApplicationException("you failed"); }

With the above setup I will never see the exception. It just hangs. However, if I change the controller to this:

return View();
var quote = await Quotes.GetQuoteById(id);

Then I get my exception. If I change the service to non-async I also get to the exception. Therefore, unlike the duplicate question referenced, I don't have an unawaited call anywhere. But the async/await is what is causing the browser to hang.

Is there a way to debug this? As an interesting aside, this only happens during debug, in production, the exception will get raised as expected.

Re-asked/Clarified/Non-Duplicate This was originally asked here but it was closed as duplicate of this question, but it isn't. Added clarification to show why it isn't. But since they closed as a definite duplicate, you can't even see it, so I had to ask as a new question.

Community
  • 1
  • 1
Tony Basallo
  • 3,000
  • 2
  • 29
  • 47
  • 3
    Don't [double post](http://stackoverflow.com/questions/28507622/why-does-awaited-never-result-in-page-completion-with-exception) please delete one of your two questions. – Scott Chamberlain Feb 15 '15 at 20:30
  • Did you try removing async / creating a different non Task action that does the same thing? This will eliminate any issues with Quotes.GetQuoteById and will just leave you with a possible deadlock issue – Mark PM Feb 15 '15 at 20:34
  • @MarkPM If I remove async/Task then it works as expected. It's the async that causes the hanging. But where can there be a deadlock issue? The above code is everything. I even created a separate controller with one single action to ensure there was nothing sneaking in. The exception in the view with an async controller cuases the page to never completely load. doesn't allow the controller – Tony Basallo Feb 15 '15 at 20:45
  • @ScottChamberlain I deleted the other one now. But only double posted because it was closed and redirected as a duplicate - as per the clarification at the end. Would have preferred to use the original question. – Tony Basallo Feb 15 '15 at 20:47
  • @TonyBasallo: In your `web.config`, what is `httpRuntime` `targetFramework` set to? – Stephen Cleary Feb 16 '15 at 00:05
  • @TonyBasallo: Can you post a short but complete repro? – Stephen Cleary Feb 17 '15 at 01:49
  • 1
    @StephenCleary I figured it out. Thanks to you :) I couldn't repo in a new solution and the one thing I wasn't all that familiar with seeing as it was new was the problem - Application Insights (MS Azure). There may be an async method that's not being awaited in my reporting code (only three places, so I doubt it) or a bug in there code. I'll look into it and see if I can figure that part out. – Tony Basallo Feb 17 '15 at 03:08

1 Answers1

0

It was related to Application Insights by Microsoft/Azure. I have to look into it a bit more (since I just removed all AI references and I need to re-install to investigate), but it might be an unawaited async call I am making into AI or a bug inside AI (it is pre-release). I am only making three calls into AI manually and I didn't receive any warning about async calls not being awaited, so I do not think this is the case and is probably a bug inside AI or by design.

Uninstalling AI let the exception flow as it normally does.

Tony Basallo
  • 3,000
  • 2
  • 29
  • 47