Skip to content

InMemoryReactiveSessionRegistry can lose a session under concurrent save/remove #19338

@junhyeong9812

Description

@junhyeong9812

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions