Tuesday, February 23, 2010

Glassfish v2.1.1 Cluster Session Replication inconsistent behavior

Everytime I take up a task on adding Cluster Support to my j2ee application, the whole experience gets quite exciting with new kinds of challenges :)

In the past, it was with Weblogic, Websphere etc...and this time it was Glassfish :)

Ok, like many of you, I managed to setup the cluster environment in glassfish and deployed "ClusterJsp" application to check out Session Failover, Load balancing etc...

What I found was that, if I keep refreshing the ClusterJsp page 5 to 10 times, my Session Id keeps changing...going to say that Glassfish lost my session somewhere in between these requests.

After googling and bing'ing a lots, I managed to find this link, which explained the issue in detail.
Basically, we should add the following snippet in sun-web.xml

<sun-web-app/>
<session-config/>
<session-manager persistence-type="replicated"/>
<manager-properties/>
<property name="relaxCacheVersionSemantics" value="true"//>
</manager-properties/>
</session-manager/>
<session-properties//>
<cookie-properties//>
</session-config/>
</sun-web-app/>

After adding the above entry, Glassfish started behaving as expected.
Now what I donot quite understand is, why was this behavior not made a default behavior !!!
I am sure there is a good reason for it, will update If I get to know.

2 comments:

Jeff said...

Hey, we're seeing a similar problem with multiple session id's, but I'm wondering, were you using sticky sessions in your load balancer? Seems based on that link that the problem might not happen if all requests for a user were routed to the same Glassfish instance.

Karthik Krishnan said...

Yes, We do use sticky sessions in our load balancer. However since, am not sure about the exact cause for the session info being lost in Glassfish, I was worried as to what if this behavior happens even If my requests go to the same server due to stick sessions. Hence to be safe, I added these entries in sun-web.xml.