views:

18

answers:

1

We are getting a TimeoutException on an MVC AsyncController in our Beta HyperV environment. Everything works fine when debugging locally, but when we deploy to the pre-production environment, we get this error:

[TimeoutException: The operation has timed out.] System.Web.Mvc.Async.WrappedAsyncResult`1.End() +129 System.Web.Mvc.Async.<>c_DisplayClass39.b_38(IAsyncResult asyncResult) +23 System.Web.Mvc.Async.<>c_DisplayClass33.b_2d() +125 System.Web.Mvc.Async.<>c_DisplayClass49.b_43() +452 System.Web.Mvc.Async.<>c_DisplayClass49.b_43() +452 System.Web.Mvc.Async.<>c_DisplayClass49.b_43() +452 System.Web.Mvc.Async.<>c_DisplayClass31.b_30(IAsyncResult asyncResult) +15 System.Web.Mvc.Async.<>c_DisplayClass24.b_1a() +31 System.Web.Mvc.Async.<>c_DisplayClass1f.b_1c(IAsyncResult asyncResult) +230 System.Web.Mvc.<>c_DisplayClass17.b_12(IAsyncResult asyncResult) +28 System.Web.Mvc.Async.<>c_DisplayClass4.b_3(IAsyncResult ar) +20 System.Web.Mvc.AsyncController.EndExecuteCore(IAsyncResult asyncResult) +53 System.Web.Mvc.Async.<>c_DisplayClass4.b_3(IAsyncResult ar) +20 System.Web.Mvc.<>c_DisplayClass8.b_3(IAsyncResult asyncResult) +42 System.Web.Mvc.Async.<>c_DisplayClass4.b_3(IAsyncResult ar) +20 System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +136

    [OutputCache(Duration = 0, NoStore = true, VaryByParam = "")]
            public void IndexAsync()
            {
                using (var context = Repository.CreateContext().CreateUnitOfWork())
                {
                    user = context.Users.Single(u => u.Username == User.Identity.Name);

                        AsyncManager.OutstandingOperations.Increment();

                        ThreadPool.QueueUserWorkItem(o => {
                            var sync = myService.DoThingsAsync(user);
                            sync.AsyncWaitHandle.WaitOne();
                            AsyncManager.OutstandingOperations.Decrement();  
                        });
                }
            }

/// IndexCompleted is never called
     public ActionResult IndexCompleted(string property)
            {
                using (var context = Repository.CreateContext().CreateUnitOfWork())
                {
                    var user = context.Users.Single(u => u.Username == User.Identity.Name);

                    var model = new MyViewModel
                    {
                        ModelProperty = user.Property
                    };

                    return View("Index", model);
                }
            }

What would be some possible causes of this error?

+1  A: 

This is the exception thrown when the asynchronous action takes longer than the configured AsyncTimeout value (which defaults to 45 seconds). You can explicitly control this value by decorating your ActionMethod with the AsyncTimeout attribute. For instance, to set the async timeout to a full minute:

[AsyncTimeout(60000)]
public void IndexAsync()
{
   ...
}

You can also use the NoAsyncTimeout attribute, but you'll be susceptible to async actions never completing and leaving your web requests in limbo.

ctsears
Thanks, that makes sense.
josefresno