spring-projects / spring-projects/spring-session

improve HazelcastSessionRepository connection exception handling

Open
#1,320 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: enhancement
Dominant language
Java
Stars
1.9k
Forks
1.2k
Avg merge
4h 27m
Merged PRs (30d)
55

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review HazelcastSessionRepository and the SessionRepositoryFilter interaction described in the issue, focusing on every access to the sessions IMap and the HazelcastException behavior. Determine the intended behavior when the Hazelcast connection is lost, then add or update coverage so requests do not fail with a 500 response in that situation.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.