Couchbase session state provider with WebForm

Hi all,

I’m currently working on session sharing between two applications: ASP.Net WebForm vs ASP.Net MVC.
Couchbase is one of the solutions. So, I’m trying to make a proof of concept.

I’m using Couchbase Server Enterprise 3.0.3 and the provider that can be found on github (https://github.com/couchbaselabs/couchbase-aspnet).

With MVC, it worked like a charm.

But, with WebForm, it fails when I try to add value on session (a simple string).
w3wp.exe take CPU: 25%, RAM: ~80Mo (>1% and >30Mo for MVC).

The problem is there:
namespace: Couchbase.AspNet.SessionState
class: SessionStateItem
method: Save(IMemcachedClient client, string id, bool metaOnly, bool useCas)

bool retval = useCas ? client.Cas(StoreMode.Set, HeaderPrefix + id, new ArraySegment(ms.GetBuffer(), 0, (int)ms.Length), ts, HeadCas).Result : client.Store(StoreMode.Set, HeaderPrefix + id, new ArraySegment(ms.GetBuffer(), 0, (int)ms.Length), ts);

The client.Store() method always returns false.
As the Save() method is called in a while loop…it become a infinite loop…
} while (!e.Save(client, id, false, exclusiveAccess && !newItem));

So, I’ve investigate a little bit.
Couchbase.AspNet use couchbase-net-client v1.3.6.
I’ve included Enyim.Caching & Couchbase in my project to find what was going on.

The problem is in Couchbase.CouchbasePool, method IMemcachedNode IServerPool.Locate(string key).
This line in particular: this.state.Locator.Locate(key);

With MVC, the type of Locator is Enyim.Caching.Memcached.VBucketNodeLocator.
But with WebForm, it’s Couchbase.CouchbasePool.NotFoundLocator
But when it’s initialized, it’s a VBucketNodeLocator
I can’t find where this.state.Locator is modified.

Is there something I miss?
Is there a newer version?

You can find my solution here

Thanks.

@kerrubin -

Thanks for the detailed report; this sounds like a bug. Would you mind creating a NCBC here: Loading... ?

The benefit of creating a ticket is that you will get alerted when the status changes.

If I read this right, you have a fix? If so, would you mind sending a pull request to GitHub - couchbaselabs/couchbase-aspnet: Couchbase Asp.Net infrastructure support?

Thanks!

-Jeff

We are working on a version for the 2.0 SDK. It’s an unofficial beta right now and can be found here:

Note that it will only work with the version 2.0.3 or greater of the Couchbase.NET SDK.

-Jeff

@jmorris

Thanks for the reply.

Alas, my solution is not a fix, just a way to reproduce the situation in case i’m doing something wrong.
So, i did not know if it’s a bug.

I stopped the investigation because of a lack of time (not my prior task, but the funnier…) and because i can’t figured out where the this.state.Locator is modified.

I’ll try again Tuesday, with my solution and i’ll give a try with the beta.
Even so, should i create an ticket?

@kerrubin -

No problem, I created the ticket for you: https://issues.couchbase.com/browse/CBASP-1

You can add yourself as a watcher to gets updates if you desire.

-Jeff

Hello again, @jmorris

I tried with the beta, it works pretty well with MVC and WebForm!

As my goal is too share session between two applications, i’ve made a very little modification in the Couchbase.AspNet.SessionState.SessionStateItem class:

        private static readonly string HeaderPrefix = (System.Web.Hosting.HostingEnvironment.SiteName ?? String.Empty).Replace(" ", "-") + "+" + System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath + "info-";
        private static readonly string DataPrefix = (System.Web.Hosting.HostingEnvironment.SiteName ?? String.Empty).Replace(" ", "-") + "+" + System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath + "data-";


        private static readonly string HeaderPrefix = string.Concat(ConfigurationManager.AppSettings["ApplicationName"], "info-");
        private static readonly string DataPrefix = string.Concat(ConfigurationManager.AppSettings["ApplicationName"], "data-");

So, in the web.config of all my applications, i’ve got an “ApplicationName” tag with the same value everywhere.
Pretty simple and nicer than the others solutions (Sql Server, State Server…).

1 Like

I wrote most of the original code after porting the old Enyim version, and I just finished updating it in my tree (pull request pending for Jeffry). You can find the latest code here:

Let me know if it works for you.

As for changing the prefixes, the only real requirement there is that the prefixes makes the keys stores in the bucket unique, which is why it automatically gets it from the site name and virtual path to make it automatically unique. But it does mean you cannot share session data between two applications. Perhaps we can make something in the factory configuration to allow you to control what would be used for the prefix? Then you can put something into the Web.config to define it.

Just added code to support this along with docs and samples in the Web.config. Now you can change the prefixes to suit and allow session or cache data to be shared between applications if you wish.

2 Likes

Hello @kendallb

I’ve try your new version, it works pretty well with MVC and WebForm!
And thanks for the prefix!