System.InvalidOperationException with Couchbase and the .Net SDK

I get the following error randomly on my production Couchbase server:

“System.InvalidOperationException
an asynchronous module or handler completed while an asynchronous operation was still pending”

I am using the latest Couchbase server and the latest version of the .Net SDK. When I run locally I do not see this error at all.

On production I have a two node Couchbase client. The config section is the following:






<enyim.com>






</enyim.com>

When I switch to the Memcache provider instead the error does not appear.

Thanks for your help. This is really a show-stopper for us.

Here is a stack trace:

Storex.Site.dll!Storex.Site.MvcApplication.Application_Error() Line 53 C#
[Native to Managed Transition]
System.Web.dll!System.Web.Util.ArglessEventHandlerProxy.Callback(object sender, System.EventArgs e) Unknown
System.Web.dll!System.Web.HttpApplication.RaiseOnError() Unknown
System.Web.dll!System.Web.HttpApplication.PipelineStepManager.ResumeSteps(System.Exception error) Unknown
System.Web.dll!System.Web.HttpApplication.BeginProcessRequestNotification(System.Web.HttpContext context, System.AsyncCallback cb) Unknown
System.Web.dll!System.Web.HttpRuntime.ProcessRequestNotificationPrivate(System.Web.Hosting.IIS7WorkerRequest wr, System.Web.HttpContext context) Unknown
System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(System.IntPtr rootedObjectsPointer, System.IntPtr nativeRequestContext, System.IntPtr moduleData, int flags) Unknown
System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(System.IntPtr rootedObjectsPointer, System.IntPtr nativeRequestContext, System.IntPtr moduleData, int flags) Unknown
[Native to Managed Transition]
[Managed to Native Transition]
System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(System.IntPtr rootedObjectsPointer, System.IntPtr nativeRequestContext, System.IntPtr moduleData, int flags) Unknown
System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(System.IntPtr rootedObjectsPointer, System.IntPtr nativeRequestContext, System.IntPtr moduleData, int flags) Unknown
[AppDomain Transition]

I created an issue to track this: http://www.couchbase.com/issues/browse/NCBC-340

I’ve run into this problem soon after I had started testing Couchbase together with ASP.NET MVC. Though I hadn’t have the time to find the fix for it (it’s some asynchronous call in DefaultHttpClient’s constructor that fails for some reason) - the workaround that works fine is to switch to i.e. RestSharpHttpClient implementation.
You can do this by adding references to Couchbase.HttpClients and RestSharp and then in web.config:

  <couchbase>
    ...
    <httpClientFactory type="Couchbase.HttpClients.RestSharpHttpClientFactory, Couchbase.HttpClients" />
  </couchbase>

Regards,
Tomasz