spring-projects / spring-projects/spring-session

Concurrent requests using MapSessionRepository leads to attributes being removed

Open
#1,849 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Describe the bug
We noticed in our app using MapSessionRepository that when the app is hit by more than one concurrent request from the same session (with a unique attribute name added to the session on the the first to finish request), the other request that finish later will revert to the state (during the commit) before the other request set the attribute, removing the newly set attribute.

To Reproduce
As seen in the sample fork, if you open two tabs to the sample app page, and set an attr "test a" on tab 1 and "test b" on tab 2, then hit "set attribute" on each tab within the same few moments, then you will see in the attr list in the page (after refreshing each page), that only one of the attributes will be set.

Expected behavior
I expected that the attribute being set would be preserved regardless of the concurrent access. From what I've read in some posts here, it seems like MapSessionRepository isn't considered "production-worthy" and perhaps this is a known issue already?

Sample
Here's a fork with a reproducible case. I modified the spring-session-sample-xml-jdbc sample to use MapSessionRepository and added a sleep inside the servlet to increase the likelihood of concurrent access.
https://github.com/twadzins/spring-session
The commit:
https://github.com/twadzins/spring-session/commit/3344c906e6b071b829dee3a192dd0c70504cace7

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 with MapSessionRepository and reproduce the race using the linked sample fork and commit 3344c906e6b071b829dee3a192dd0c70504cace7. Trace the session commit behavior during two concurrent requests, then verify that distinct attributes are preserved after both requests complete and the pages are refreshed.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend
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.