Skip to content

Conversation

@kaiinkinen
Copy link

Including the jvmRoute as part of the redis key prevents migrating the session to another node. This applies both to failover because a node dies, as well as normal round-robin load balancing.

Quoting the memcached session plugin FAQ (https://code.google.com/p/memcached-session-manager/wiki/FAQ):

If you want to go for the servlet filter with sticky sessions, you also need to strip the jvmRoute off the sessionId to get the memcached key (in the case tomcats are configured with a jvmRoute). Otherwise, when the sessionId including the jvmRoute would be used as memcached key, the key would change on a tomcat failover as the jvmRoute is then changed to the one of the tomcat that is taking over the session.

This pull request modifies the key used in redis by stripping the jvmRoute from it. This way any node in the cluster can fetch the same value using the session id. Stripping the key happens both for newly generated session ids, as well as the ones coming from the customer.

This current implementation assumes that if the jvmRoute is not set, i.e. is null, then the session id is not tampered with.

The pull request contains some very basic sanity tests for the strip method, to make sure no unwarranted exceptions are thrown, and that the stripping logic works for various special cases.

Kai Inkinen added 4 commits May 5, 2015 10:00
…l session id

* Redis stores the id without the jvmRoute, since having it as part of the key effectively makes the session valid only on node with this jvmRoute
* Customer still gets the original session id, including the jvmRoute, since this value is used for load balancing e.g. in mod_jk
* Don't just log the exception, but also include the session id being handled at the moment
* Log the action we're undertaking (add/remove)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant