Session state during failover

#1

I was doing some testing with the couchbase iis session replacement. I’m using the standard repo (https://github.com/couchbaselabs/couchbase-aspnet) and I have a test site using couchbase. I was testing the failover with 3 nodes, when I stop a service on a node and try to navigate the site during that time I lose my session. If I wait and restore the service before failover I keep my session intact.

I found this thread from over 2 years ago (http://www.couchbase.com/communities/q-and-a/what-happens-when-node-cluster-goes-down) where someone is talking about losing access to some data while a node is failing over. I think that in my tests the server can’t get the data for the server and thinks it doesn’t exist so it creates a new session. It seems related to what was going on 2 years ago but in that instance it was ok. For sessions I want to have as close to 100% up time as possible.

Is it my setup or the session state provider that is the problem? Thanks for any insight into this.

1 Like
#2

Thanks for you post - I am experiencing the same. Did you ever get this resolved?
cb 3.0.1

#3

One thing you may want to look into is use of the durability requirements with ReplicateTo.ONE. This would give you higher availability at the cost of slightly higher latency, since you’re waiting until the session data is in memory in two locations.

That may require some porting of the aspnet session provider to the 2.0 client, but I’m not sure. @jmorris, can you advise?

#4

We did figure this out . To quote the dev,

While the system is in the middle of an automatic failover, the header was for a session was coming back null and thus presenting the user with an empty session. If the header comes back null, we now loop around until its not null.

On SessionStateItem.cs we changed lines around 115 from where the if (header.Result == null)

if (header.Result == null){
    //if the header comes back null, couchbase is in a failure state
    //must take caution not to present the user with a falsely null session.
        do
        {
            Thread.Sleep(5000);
            //loop header call until couchbase finishes failover and is back online
            header = client.GetWithCas<byte[]>(headerPrefix + id);
        } while (header.Result == null);
        //header is no longer null, continue to memorystream
}

I hope this helps. I should also mention, we had other issues that prevents us from using this in production.

#5

Thank you for the reply!
I’m struggling with this asp.net session provider:
And it is not just in the failover scenario you described. If our app is updated (web site is updated), the session stops working

CB 3.0.1
Couchbase client api - 2.0.2
Coucbase.AspNET (version 1.2.3) - https://github.com/couchbaselabs/couchbase-aspnet version

Session State Server - I was able to use the couchbase as the session state server. At first, I encountered a problem when using the same configuration section the data cache is using. I was able to get around the error by creating a separate configuration section for the session state server.

One problem though, It appears there’s a bug on couchbase and IIS. The bug happens whenever a configuration file (e.g. Web.config, AppSetting.config) is updated OR overwritten - which in our case happens every deployment. The application will error indicating the couchbase node failed. The error goes away after I reboot the couchbase server.

Based on their support, this error was fixed on version 1.3.4 but we’re currently using version 1.3.10 and we’re still seeing the error.
http://review.couchbase.org/#/c/31007/

We updated the CouchbaseClient API that we’re using. Originally, we’re using 1.2.10 version but they have a new major release called CouchbaseClient 2.0.2. Unfortunately, same results - same error.

Looks like the problem is in the Coucbase.AspNET.
Should I try this one ? https://github.com/evereq/couchbase-aspnet
looks like mostly the same except for the addtion of compression and logging).

The big question is this: is the Couchbase.AspNET ready for prime time, in a live application? Do I have a settings/config/usage problem? Love to get this to work, but looks shakey to me.
You mentioned that you did not use this in production. May I ask you what you did use for session state (I assume a .net app) in production?

Thanks again,
Tom D

#6

@tommyjd

This is a bug, can you create an NCBC for it?

The session provider hasn’t yet been updated to the version 2.0 of the SDK, which is why the error still exists.

Thanks,

Jeff

#7

@tommyjd

The session state provider has been updated to use Couchbase SDK 2.0: https://github.com/couchbaselabs/couchbase-aspnet/tree/2.0

It still needs some more refactoring, but it does work. Note a couple of changes:

  1. The first configured bucket in the couchbase section will be used as the caching/session bucket

  2. You must explicitly initialize Couchbase.ClusterHelper in the global.asax:

    protected void Application_Start()
    {
    ClusterHelper.Initialize(“couchbase-caching”);
    AreaRegistration.RegisterAllAreas();
    RegisterGlobalFilters(GlobalFilters.Filters);
    RegisterRoutes(RouteTable.Routes);
    }

Your config will also need to be changed to the SDK 2.0 syntax. Let me know if you run into any problems.

-Jeff