Hi,
I am using hazelcast and hazelcast-wm 3.5 with a WebLogic container.
Would it be possible for someone clarify the behaviour of the session expiry?
I would like to set the time-to-live-seconds on the distributed map to 0 and use the session timeout configured in the web application XML.
The documentation indicates this is supported:
Hazelcast automatically removes sessions from the cluster if the sessions are expired on the Web Container. This removal is done by com.hazelcast.web.SessionListener, which is an implementation of javax.servlet.http.HttpSessionListener.
Default session expiration configuration depends on the Servlet Container that is being used. You can also define it in your web.xml.
The Javadoc on WebFilter#destroySession also implies this:
@param invalidate {@code true} if the session has been invalidated and should be destroyed on all nodes in the cluster; otherwise, {@code false} to only remove the session globally if this node was the final node referencing it
The highlighted part is of particular interest to me as I cannot work out how this is being enforced. The only consequence I can see of setting this flag to false is that the DeleteSessionEntryProcessor will set the session state back on the map against the same key (instead of removing it).
Thus the behaviour is as follows:
- Session expires after time defined in web.xml (session-config/session-timeout).
- Container invokes com.hazelcast.web#sessionDestroyed.
- WebFilter#destroySession invoked (with invalidate flag set to false).
So far, so good.
However on the on the next request following destruction of the session:
- The browser will still send the hazelcast web session cookie in the HTTP request (with the same session ID).
- WebFilter.RequestWrapper#getOrCreateHazelcastSession is invoked on first session access.
- #getSessionWithId will return null, because the session will have been removed from the sessions map following the timeout (WebFilter#destroySession).
- A new HazelcastHttpSession object will be instantiated (via createNewSession and createHazelcastHttpSession).
- The HazelcastHttpSession#buildLocalCache will populate all session attributes from the session id read from the cookie in step one. (Oops!)
From the code I can understand why
Thus nothing appears to have expired - the session and all attributes remain in tact.
Obviously you can get different behaviours by altering the time-to-live-seconds of the distributed map to be higher/lower/equal to the session-timeout, but as stated at the start I would prefer (if possible) to configure this in one place.
Thank you in advance for any contributions.