spring-projects / spring-projects/spring-security
InMemoryReactiveSessionRegistry can lose a session under concurrent save/remove
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.6k
- Forks
- 6.3k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 52
Description
Describe the bug
InMemoryReactiveSessionRegistry can lose a session when saveSessionInformation and removeSessionInformation run concurrently for the same principal.
The per-principal session set is updated non-atomically:
saveSessionInformationcalls.add(...)outside thecomputeIfAbsentmapping function.removeSessionInformationprunes the principal key with a non-atomicget→isEmpty()→remove(principal).
To Reproduce
Principal P owns one session S1:
- Thread A removes
S1— the set becomes empty, and A is about to remove keyP. - Thread B saves
S2—computeIfAbsent(P)still sees keyP, returns the same set, and addsS2. - Thread A removes key
P— the set{S2}is orphaned;getAllSessions(P)returns empty andS2is lost.
A latch-synchronized concurrent save/remove stress test reproduces this.
Expected behavior
A session added concurrently is not lost. The blocking SessionRegistryImpl already performs these updates atomically via compute/computeIfPresent; the reactive registry should do the same.
I will submit a PR with a regression test.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate InMemoryReactiveSessionRegistry and compare its saveSessionInformation and removeSessionInformation updates with SessionRegistryImpl, especially the compute and computeIfPresent usage mentioned in the issue. Add the regression test described in the issue, then run the relevant Spring Security session registry tests and confirm a concurrently added session remains discoverable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- authentication, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100