yusuf
yusuf

Reputation: 73

User session closed after 20 minutes

I have configured a 20 minute session timeout in the web.xml file of my war. But I am calling my servlet to keep the session active after 20 minutes using this JavaScript code:

setInterval(function () {
    $.get("sessionKeepAlive");
}, 240000);

Everything is working fine in the Dev environment, but in QA it's not working. We are using a load-balancer in QA. I want to know if there is anything that we can change in the server configuration cse to get around this issue.

web.xml:

<session-config>
    <session-timeout>10</session-timeout>
</session-config>

Upvotes: 1

Views: 263

Answers (2)

yusuf
yusuf

Reputation: 73

Thanks all for your reply :) I just checked and found that the session stickiness time on the load-balancer is 3 minutes. This means the load-balancer can send the request to any server after 3 minutes even if the session is active.

For time being I have changed the js method, and later I will update the session active time on the load-balancer.

setInterval(function () {
    $.get("sessionKeepAlive");
}, 240000);

Upvotes: 0

Crollster
Crollster

Reputation: 2771

Ok there can be a number of things to look at:

  1. Since you are using a Load Balancer, it suggests you are using multiple Java servers (app servers or servlet containers) - you should ensure your Session sharing (clustering) mechanism is properly configured. Also, your back-end server may require you to add the <distributable /> tag to your web.xml. (The downside of this approach is that sharing sessions across more than a handful of back-end servers is not really advisable, unless absolutely necessary)

  2. An alternative option to using clustering/session sharing, as mentioned by @piet.t is to ensure that Session stickiness is enabled on your load balancer - this would ensure that requests using the same session always go back to the same server. (The downside of this approach is that you risk losing a lot of sessions if 1 server dies)

  3. As @JB Nizet suggested in the comments above, you should ensure your AJAX GET request is not being returned from the browser cache - this is sometimes done by adding a random number to each GET request (eg. The time in milliseconds)

Upvotes: 1

Related Questions