spring-projects / spring-projects/spring-session

SpringSessionBackedSessionInformation.EXPIRED not used in expired session clean up

Open
#3,249 0 comments 0 reactions 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

I use Jdbc session, I want to mark some sessions as expired.
So I call

//private val sessionRegistry: SessionRegistry,

sessionRegistry.getAllSessions("login", false).forEach {
               it.expireNow()
    }

getAllSessions returns SpringSessionBackedSessionInformation objects.
Calling expireNow on them calls super.expireNow and adds the SpringSessionBackedSessionInformation.EXPIRED attribute.
The times of the session are not touched in DB.

So far so good.

When the clean up job launches in JdbcIndexedSessionRepository it only checks the expiry date, so expired sessions are kept in db.

Example data from DB :

"PRIMARY_ID","SESSION_ID","CREATION_TIME","LAST_ACCESS_TIME","MAX_INACTIVE_INTERVAL","EXPIRY_TIME","PRINCIPAL_NAME"
a296354c-d86a-49ac-9ff5-c9593eec64f4,ba25a393-db6f-4e40-a467-33361df132a5,1729712977529,1729753828691,604800,1730358628691,toto

corresponding attribute :

"SESSION_PRIMARY_ID","ATTRIBUTE_NAME","ATTRIBUTE_BYTES"
"a296354c-d86a-49ac-9ff5-c9593eec64f4",org.springframework.session.security.SpringSessionBackedSessionInformation.EXPIRED,"true"

Expected behavior

clean up cron should delete sessions based on expiry time but also based on the presence of the SpringSessionBackedSessionInformation.EXPIRED attribute.

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 JdbcIndexedSessionRepository and trace the cleanup job's expiry checks, then inspect how SpringSessionBackedSessionInformation.EXPIRED is stored and exposed. The work is complete when cleanup removes sessions marked with that attribute as well as sessions past their expiry time, with regression coverage for both cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend, database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.