spring-projects / spring-projects/spring-security

InMemoryReactiveSessionRegistry can lose a session under concurrent save/remove

Open
#19,338 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
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:

  • saveSessionInformation calls .add(...) outside the computeIfAbsent mapping function.
  • removeSessionInformation prunes the principal key with a non-atomic getisEmpty()remove(principal).

To Reproduce

Principal P owns one session S1:

  1. Thread A removes S1 — the set becomes empty, and A is about to remove key P.
  2. Thread B saves S2computeIfAbsent(P) still sees key P, returns the same set, and adds S2.
  3. Thread A removes key P — the set {S2} is orphaned; getAllSessions(P) returns empty and S2 is 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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.