improve HazelcastSessionRepository connection exception handling
The current implementation of HazelcastSessionRepository does not handle any HazelcastException when accessing the sessions map.
In the case of a hazelcast server connection lost, this causes all requests to return 500 error status.
The reason for this is the SessionRepositoryFilter calls the HazelcastSessionRepository early in the request cycle which throws an Exception when accessing the sessions IMap.
Since the HazelcastSession is only visible in the package i had to completely replace the current HazelcastSessionRepository with my own implementation to add additional exception handling.
Example code for Hazelcast Exception Handling:
@Override
public HazelcastSession findById(String id) {
try {
MapSession saved = this.sessions.get(id);
if (saved == null) {
return null;
}
if (saved.isExpired()) {
deleteById(saved.getId());
return null;
}
return new HazelcastSession(saved);
} catch(HazelcastException e){
LOG.error("hazelcast session failed to find", e);
return null;
}
}
I've added a try catch around every this.sessions access. I'm not sure if this is the right approach i would appreciate any better suggestions to prevent this situation. Thanks in advance.
Thanks for the report @michaelhaessig.
We'll need to take a look at this one from a higher level, and see how other session stores behave in the similar situation.
makes sense if this could be handled in the SessionRepositoryFilter so all SessionRepository implementations can benefit.