redisson: Redisson Session Manager session attributes problem
We want to use Redisson Session Manager as a Tomcat Session Manager. It is essential that Redisson is configured as a shared instance in Tomcat since plugins that need access to a shared Session will be used. We found a behavior that could potentially indicate a bug in the session management.
A simplified diagram of our system is shown in the following figure.
The repository with the test project based on Spring Boot is here: https://github.com/DJakosa/redisson-test
Expected behavior
All apps should use the same shared Session which is resolved based on JSESSIONID
cookie. The Session should contain attributes with latest values that also include session scoped beans.
Actual behavior
When the readMode
property of Manager configuration in context.xml
is set to REDIS
, behavior seems to be as expected (see value of session_attribute_count
in response or logs which is incremented by 1 for every request). But with REDIS
read mode, session scoped beans are not stored as session attributes.
However, if we change readMode to MEMORY
, session scoped beans are stored as session attributes. Behavior is as expected if requests are sent to apps with the same context path (app-a in Tomcat 1 and Tomcat 2). When the request is sent to a different app (e.g. to app-b after being sent to app-a before), the second app (app-b) gets session attributes with values of the last request to the first app (app-a). If the request is sent to the first app (app-a) again, the session attribute values such as session_attribute_count
will not continue from the values that the second app (app-b) had set. It also seems that session attributes that are added to the Session by the second app (such as session_attribute_app_b_value
) are not available in the first app.
Steps to reproduce or test case
- Checkout repository with the test project
- Build project with maven (
mvn clean verify
) to get war files at./app-a/target/app-a.war
and./app-b/target/app-b.war
- Run
docker-compose up
from project root to set up stack with two Tomcats and Redis - Send requests to following endpoints (use the same session identifier) and inspect response and logs:
- http://localhost:8090/app-a/session-values (app-a.war in Tomcat 1)
- http://localhost:8091/app-a/session-values (app-a.war in Tomcat 2)
- http://localhost:8091/app-a2/session-values (app-a.war in Tomcat 2 at context /app-a2)
- http://localhost:8091/app-b/session-values (app-b.war in Tomcat 2)
- Set different
readMode
property value (REDIS
orMEMORY
), redeploy docker stack, flush Redis and repeat step 4.
Redis version 5.0.7
Redisson version 3.11.6
Redisson configuration
See ./volume/conf/redisson.yaml
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 31 (18 by maintainers)
Commits related to this issue
- Fixed - multiple Tomcat requests share different instances stored in the same session in readMode=REDIS #2476 — committed to redisson/redisson by deleted user 4 years ago
it works!
@alexbosy @DJakosa @luiszimmermann
I attached new version which fixes the issue. Could you give it a try?
redisson-tomcat-8-3.13.4-SNAPSHOT.jar.zip
Right now I am only using the redisson in tomcat, following this strategy, without putting any redisson dependency in my app (grails 2.5.6/spring 4.2.9).
Should I add the redisson in my app and create the Configuration files with
EnableRedissonHttpSession
to make thereadMode="REDIS"
works with mutable session?Confirmed in my tests.
context.xml with
<Manager className="org.redisson.tomcat.RedissonSessionManager" configPath="${catalina.base}/conf/redisson.yaml" broadcastSessionEvents="true" readMode="REDIS" updateMode="DEFAULT" />
With
readMode="MEMORY"
the flash messages session attributes works as expected.