question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to set a session to timeout in 2 minutes as I set maxInactiveInterval(in ROOT.xml)?

See original GitHub issue

Hi, I’m testing with sharing sessions using tomcat-redis-session-manager jar. Sessions are stored in Redis as I expected but session timeout is not working.

I understand that if I set maxInactiveInterval=120(ROOT.xml) then session will be expired in 2 minutes. But whether or not I configures session maxInactiveInterval, session expired in 5 minutes. It seems maxInactiveInterval doesn’t work. Did I misunderstand something?

I’m wondering if I programatically set the time limit of inactivity by

request.getSession().setMaxInactiveInterval(7* 60); //7 minutes

I think session timeout minutes this configuration has high priority but session expired in 5 minutes(web.xml configurataion).

Currently, we have our session timeout set in the Catalina/ROOT.xml file, like this

<Context path="/">
  <Valve className="com.radiadesign.catalina.session.RedisSessionHandlerValve" />
  <Manager className="com.radiadesign.catalina.session.RedisSessionManager"
    host="x.x.x.x."
    port="6380"
    password="xxxx"
    database="0"
    maxInactiveInterval="120" />
</Context>

and myapplication/web.xml file

<session-config>
    <session-timeout>5</session-timeout>
  </session-config>
...



* Using

Tomcat 7 version
Java 1.7.0_65 version
tomcat-redis-session-manager-1.2-tomcat-7-java-7.jar
jedis-2.1.0.jar
commons-pool-1.6.jar

I added these jars in Tomcat/lib and reboot the server. 

Thank you in advance.

Issue Analytics

  • State:open
  • Created 9 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ghostcommented, Jan 9, 2017

Hi All,

Noted the following. The session-timeout configuration in the web.xml should be used. “maxInactiveInterval” is not used any more.

WARNING: Manager.setMaxInactiveInterval() is deprecated and calls to this method are ignored. Session timeouts should be configured in web.xml or via Context.setSessionTimeout(int timeoutInMinutes)

1reaction
ozvalecommented, Nov 30, 2016

I’ve solved this problem.

find class RedisSession,add following codes.

public void writeObjectData(java.io.ObjectOutputStream out) {
		super.writeObjectData(out);
		out.writeLong(this.getCreationTime());
               //read and write maxInactiveInterval to redis
		out.writeInt(getMaxInactiveInterval());
}
public void readObjectData(java.io.ObjectInputStream in)  {
		super.readObjectData(in);
		this.setCreationTime(in.readLong());
                // read and set maxInactiveInterval from redis
		this.setMaxInactiveInterval(in.readInt());
}

find RedisSessionManager,find following codes in method saveInternal.

  log.trace("Setting expire timeout on session [" + redisSession.getId() + "] to " + getMaxInactiveInterval());
      jedis.expire(binaryId, getMaxInactiveInterval());

modify like this

if (redisSession.getMaxInactiveInterval() > 0) {
            log.trace("Setting expire timeout on session [" + redisSession.getId() + "] to " +redisSession.getMaxInactiveInterval());         
           jedis.expire(binaryId, redisSession.getMaxInactiveInterval());
}

find sessionFromSerializedData from RedisSessionManager.do as the following codes.

session.setId(id);
session.setNew(false);
// session.setMaxInactiveInterval(getMaxInactiveInterval());
session.access();
session.setValid(true);
session.resetDirtyTracking();
Read more comments on GitHub >

github_iconTop Results From Across the Web

SessionTimeout: web.xml vs session.maxInactiveInterval()
My container is WebLogic. Currently, we have our session timeout set in the web.xml file, like this <session-config> <session-timeout> ...
Read more >
RE: Icefaces "User Session Expired" - Liferay Community
The default is 30 minutes and the setting in the web.xml of each individual portlet ... changing the session timeout in root web.xml...
Read more >
Setting the session timeout in the server.xml file - IBM
In a single-server environment, log on to the server as a root user. Enter the following command to ensure that the ioc.user user...
Read more >
How to configure the session timeout in servlet - Mkyong.com
The session timeout in a web application can be configurable in two ways ... the value in deployment descriptor (web.xml) is in “minute”, ......
Read more >
15.2. Configure the HTTP Session Timeout
Application - defined in the application's web.xml configuration file. · Server - specified via the default-session-timeout attribute. This setting is only ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found