spring-projects / spring-projects/spring-session

Save session on Redis RedisSession.saveDelta

Open
#311 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
1.9k
Forks
1.2k
Avg merge
4h 27m
Merged PRs (30d)
55

Description

I'm using Spring Session version 1.0.2.RELEASE and I found a problem when RedisSession save delta

If you add a new value on session (RedisSession) the session save correctly on Redis, because we have this code below:

        public void setAttribute(String attributeName, Object attributeValue) {
            cached.setAttribute(attributeName, attributeValue);
            delta.put(getSessionAttrNameKey(attributeName), attributeValue);
        }

But if in other request I get a object in this session, change some property of this object, the session on redis is not updated.

The problem is when we create RedisSession passing MapSession, this map is setter on variable "cached" but the values of "cached" doesn't pass to "delta"

Example to reproduce the problem:
POJO

public class NamePOJO implements Serializable {
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

Controller

    ...
    @RequestMapping(value = "/changeSession/{value}")
    public void changeOnSession(@PathVariable(value  = "value") String value, HttpServletRequest request) throws IOException {
        final String sessionName = "SESSION_NAME";

        NamePOJO oldVersion;
        if (request.getSession().getAttribute(sessionName) == null) {
            oldVersion = new NamePOJO();
            oldVersion.setName(value);
            request.getSession().setAttribute(sessionName, oldVersion);
        }

        oldVersion = (NamePOJO)request.getSession().getAttribute(sessionName);

        log.info(String.format("Old name %s new name %s", oldVersion.getName(), value));
        oldVersion.setName(value);
    }
    ...

1* Request (/changeSession/Test)
Output: Old name Test new name Test
2* Request (/changeSession/Changed)
Output: Old name Test new name Changed
3* Request (/changeSession/Changed)
Output: Old name Test new name Changed

On the 3* request, the old name doesn't changed

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

Start at RedisSession.saveDelta and the RedisSession construction from MapSession described in the issue. Reproduce the three /changeSession/{value} requests with the provided NamePOJO and verify that the changed name is persisted so the third request reports the updated value.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.