2

Trying to setup a tomcat cluster with non-sticky sessions using redis.

Trying to use: https://github.com/redisson/redisson/wiki/14.-Integration%20with%20frameworks#145-spring-session

The 2 jar files are added. Using Tomcat 7.

context.xml:

   <Manager className="org.redisson.tomcat.RedissonSessionManager"
                 configPath="${catalina.base}/conf/redisson.yml"
                 readMode="REDIS"

redisson.yml:

---
sentinelServersConfig:
  idleConnectionTimeout: 10000
  pingTimeout: 1000
  connectTimeout: 10000
  timeout: 3000
  retryAttempts: 3
  retryInterval: 1500
  reconnectionTimeout: 3000
  failedAttempts: 3
  password: null
  subscriptionsPerConnection: 5
  clientName: null
  loadBalancer: !<org.redisson.connection.balancer.RoundRobinLoadBalancer> {}
  subscriptionConnectionMinimumIdleSize: 1
  subscriptionConnectionPoolSize: 50
  slaveConnectionMinimumIdleSize: 10
  slaveConnectionPoolSize: 64
  masterConnectionMinimumIdleSize: 10
  masterConnectionPoolSize: 64
  readMode: "SLAVE"
  subscriptionMode: "SLAVE"
  sentinelAddresses:
  - "redis://redis-sentinel:26379"
  masterName: "redismaster"
  database: 0
threads: 0
nettyThreads: 0
codec: !<org.redisson.codec.JsonJacksonCodec> {}
useLinuxNativeEpoll: false

Redis is up. It finds the servers. I don't see any errors.

Now when I go to say the manager to test. It will do a round-robin load balance. I log into the first server and I get a session. I refresh, it doesn't seem to pull up the correct session and acts like i never logged in. The cookie is still set. I refresh a few times to get back to the first server and I'm still logged in.

Any ideas about what I am missing?

Matt
  • 7,049
  • 7
  • 50
  • 77
  • did you find the solution? – Kodin Aug 27 '18 at 21:40
  • @Novice_JS no, I never found a solution for this unfortunately. – Matt Aug 28 '18 at 10:43
  • any alternatives? or you stopped using redisson. – Kodin Aug 28 '18 at 13:46
  • @Novice_JS I couldn't use sessions. So at the time it was just dropped. So I really don't have an answer for you. We were reprogramming the entire solution anyway, so I figured we would revisit at that time. There are plugins out there, but I could never get any of them to work. – Matt Aug 30 '18 at 04:55
  • Thanks @Matt. I ended up editing redisson-tomcat library and works fine for me now. – Kodin Aug 30 '18 at 19:06
  • @Novice_JS Do you mind posting what you did in case someone else has the issue and ill mark yours as correct. I probably won't even need the solution for myself, but somebody might. – Matt Aug 31 '18 at 11:49

1 Answers1

1

Update:

My app was using HttpServletRequest.login() method for user login. This method invalidates the previous session user was on and creates new session for security reasons after login. This change of session when user was logging in was creating the issue of user not being able to login ever. When i removed HttpServletRequest.login() method then user was able to login fine and maintain the session even after login.

In short, Redisson doesn't work fine if you use HttpServletRequest.login().


I forked the redisson project (you can find the link below) and did some changes of my own. I don't know if they are optimal but works fine for me. I was facing the same situation as you. Below were my settings

  1. Two tomcat configured with 3 redisson sentinel.
  2. One IIS load balancer in front of two tomcats which was doing round robin load balancing.

Issue: When user try to login to the web app then first request of login seems to reach first tomcat and as soon as the page refreshes after login second request seems to hit the second tomcat because of round robin balancing. Redisson somehow was not able to pull the session stored in redis by first tomcat and serve it up when page refreshes and request goes to second tomcat. Hoewever, a second empty session was created by redisson and the user never gets login.

Solution: If redisson is not able to find session using current catalina managerBase then search for the session in redis itself and if you are able to find it then make it available and populate all the session attributes from that retrieved session. Furthermore, If session is not present in redis then redisson can go ahead and create new session.

Changes are in load method in RedissonSession.java and findSession method in RedissonSessionManager.java files in tomcat 8 folder.

P.S. Not tested for optimal performance and other issues, but till now this seems to resolve the problem i was having. Any comments and forks are appreciated.

redisson forked library

Kodin
  • 772
  • 8
  • 23