Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An "IllegalStateException: Session was invalidated" - exception is thrown after session was already invalidated #2893

Open
stefan-g opened this issue Mar 20, 2024 · 1 comment
Labels
status: waiting-for-triage An issue we've not yet triaged type: bug A general bug

Comments

@stefan-g
Copy link

stefan-g commented Mar 20, 2024

I have a /logout rest endpoint that invalidates a session by using HttpSession#invalidate(). Sometimes (10 out of 1000 requests) the following IllegalStateException is thrown.

java.lang.IllegalStateException: Session was invalidated
	at org.springframework.session.data.redis.RedisSessionRepository.save(RedisSessionRepository.java:122)
	at org.springframework.session.data.redis.RedisSessionRepository.save(RedisSessionRepository.java:42)
	at org.springframework.session.web.http.SessionRepositoryFilter$SessionRepositoryRequestWrapper.commitSession(SessionRepositoryFilter.java:227)
	at org.springframework.session.web.http.SessionRepositoryFilter.doFilterInternal(SessionRepositoryFilter.java:145)
	at org.springframework.session.web.http.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:82)
	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:352)
	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:268)
			2 lines skipped for [org.apache.catalina]
	at org.springframework.web.filter.ServerHttpObservationFilter.doFilterInternal(ServerHttpObservationFilter.java:109)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
			2 lines skipped for [org.apache.catalina]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
			2 lines skipped for [org.apache.catalina]
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
			17 lines skipped for [org.apache.catalina, org.apache.tomcat, org.apache.coyote]
	at java.base/java.lang.Thread.run(Thread.java:840)

The exception occurs in combination with spring cloud gateway (netflix). It's seems that the way spring cloud gateway is forwarding the request causes some troubles in this case.

The used components are spring boot 3.2.3, spring cloud dependencies 2023.0.0, Redisson

I found a similar case here spring-projects/spring-security#9128 (comment) but there it is related to spring security.

The exception can be reproduced by the following demo app (tested on windows 11). check readme.md for details.

@stefan-g stefan-g added status: waiting-for-triage An issue we've not yet triaged type: bug A general bug labels Mar 20, 2024
@stefan-g stefan-g changed the title An IllegalStateException: Session was invalidated is thrown after session is manually already invalidated An "IllegalStateException: Session was invalidated" - exception is thrown after session was already invalidated Mar 20, 2024
@petervanwylen
Copy link

petervanwylen commented Aug 13, 2024

I'm having this same error in spring boot 3.3.2 but not with spring cloud but spring session redis backed by AWS serverless redis. I don't really understand it, and it seems like an invalidated session should be handled by default without throwing errors?

This seems related to #1277 possibly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants