spring-projects / spring-projects/spring-session
MaxInactiveInterval is not being set in session in SessionDestoyedEvent
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.9k
- Forks
- 1.2k
- Avg merge
- 4h 27m
- Merged PRs (30d)
- 55
Description
Hi. Let me explain what i'm facing. In my project i am using Spring websocket. After adding this i noticed SessionDestroyedEvent is not working anymore when user logs out. long story short websocket session and http session weren't in sync was the cause of problem and solution to it was using spring session project with redis. i used that and problem resolved but in my SessionDestroyedEvent i had a code that was calculating that user has logged out or his session has expired and then logged this to database.
@EventListener(SessionDestroyedEvent.class)
public void OnSessionDestroyedEvent(SessionDestroyedEvent ev) {
HttpSessionDestroyedEvent event = (HttpSessionDestroyedEvent) ev;
Long lastAccessedTime = event.getSession().getLastAccessTime();
Long currentTime = Calendar.getInstance().getTimeInMillis();
if (((currentTime - lastAccessedTime) / 1000) >= event.getSession().getMaxInactiveInterval()) {
// means session has expired
} else {
// means user loged out.
}
}
and in application.yml
spring.session.timeout = 60
with these my listener works and session expires after a minute too but event.getSession().getMaxInactiveInterval() always return 0 and not the timeout i set.
i don't know if this is a bug or i have to use some other method to achieve this. googling and searching issues in here didn't help.
one more thing is that by debugging i found a property called defaultMaxInactiveInterval in HttpSessionDestroyedEvent object but didn't know how to access that. Thanks in advanced.
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
Start with the SessionDestroyedEvent and HttpSessionDestroyedEvent APIs used by the listener, then compare their session values with the 60-second timeout in application.yml. Reproduce the logout and expiry paths and verify whether the configured max inactive interval is available when the event is handled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100