spring-projects / spring-session

Spring Session
https://spring.io/projects/spring-session
Apache License 2.0
1.86k stars 1.11k forks source link

Unable to publish SessionDestroyedEvent #1198

Closed pch851130 closed 5 years ago

pch851130 commented 6 years ago

when spring boot is upgraded from 1.5.X to 2.X, which causes above warning. is there any way to stop it? warning is output every 3 seconds.

018-09-17 02:19:39.536  WARN [enerContainer-3] s.s.d.r.RedisOperationsSessionRepository : Unable to publish SessionDestroyedEvent for session e8c84161-028c-46e5-b3a8-823c7c2f146d at org.springframework.session.data.redis.RedisOperationsSessionRepository.(RedisOperationsSessionRepository.java:520) 
2018-09-17 02:19:47.379  WARN [enerContainer-7] s.s.d.r.RedisOperationsSessionRepository : Unable to publish SessionDestroyedEvent for session 435fd247-a9fa-4494-b5fd-d6c187c094ee at org.springframework.session.data.redis.RedisOperationsSessionRepository.(RedisOperationsSessionRepository.java:520) 
2018-09-17 02:19:49.682  WARN [enerContainer-9] s.s.d.r.RedisOperationsSessionRepository : Unable to publish SessionDestroyedEvent for session 71ec2f61-18e2-4a9a-81d6-a713d0516101 at org.springframework.session.data.redis.RedisOperationsSessionRepository.(RedisOperationsSessionRepository.java:520) 
2018-09-17 02:20:00.090  WARN [nerContainer-15] s.s.d.r.RedisOperationsSessionRepository : Unable to publish SessionDestroyedEvent for session 1dd02046-6f92-400f-ae1d-005e481ed4f2 at org.springframework.session.data.redis.RedisOperationsSessionRepository.(RedisOperationsSessionRepository.java:520) 
2018-09-17 02:20:00.156  WARN [nerContainer-16] s.s.d.r.RedisOperationsSessionRepository : Unable to publish SessionDestroyedEvent for session 027aad73-31d0-4e92-98c4-b7b251cdd0c0 at org.springframework.session.data.redis.RedisOperationsSessionRepository.(RedisOperationsSessionRepository.java:520) 
2018-09-17 02:20:17.047  WARN [nerContainer-23] s.s.d.r.RedisOperationsSessionRepository : Unable to publish SessionDestroyedEvent for session 3e0c514e-6435-457b-83e0-7b6bc57e7e9c at org.springframework.session.data.redis.RedisOperationsSessionRepository.(RedisOperationsSessionRepository.java:520) 
2018-09-17 02:20:24.864  WARN [nerContainer-29] s.s.d.r.RedisOperationsSessionRepository : Unable to publish SessionDestroyedEvent for session b356a6a5-e5b1-4269-9a52-1ea5453ac177 at org.springframework.session.data.redis.RedisOperationsSessionRepository.(RedisOperationsSessionRepository.java:520) 
2018-09-17 02:20:25.064  WARN [nerContainer-30] s.s.d.r.RedisOperationsSessionRepository : Unable to publish SessionDestroyedEvent for session ccd04689-f11f-454f-94ea-3365ca362ec6 at org.springframework.session.data.redis.RedisOperationsSessionRepository.(RedisOperationsSessionRepository.java:520) 
2018-09-17 02:20:28.112  WARN [nerContainer-31] s.s.d.r.RedisOperationsSessionRepository : Unable to publish SessionDestroyedEvent for session d30dbf99-8cf8-4886-83db-4855054d9628 at org.springframework.session.data.redis.RedisOperationsSessionRepository.(RedisOperationsSessionRepository.java:520) 
2018-09-17 02:20:30.346  WARN [nerContainer-33] s.s.d.r.RedisOperationsSessionRepository : Unable to publish SessionDestroyedEvent for session 8493a12d-8e55-4905-84ef-95072aed2940 at org.springframework.session.data.redis.RedisOperationsSessionRepository.(RedisOperationsSessionRepository.java:520) 
2018-09-17 02:20:41.392  WARN [nerContainer-37] s.s.d.r.RedisOperationsSessionRepository : Unable to publish SessionDestroyedEvent for session 2c80ef32-0221-40e0-b0c4-037ef1a6e152 at org.springframework.session.data.redis.RedisOperationsSessionRepository.(RedisOperationsSessionRepository.java:520) 
2018-09-17 02:20:49.203  WARN [nerContainer-43] s.s.d.r.RedisOperationsSessionRepository : Unable to publish SessionDestroyedEvent for session 3823286e-9f19-462f-8773-5e68e087c650 at org.springframework.session.data.redis.RedisOperationsSessionRepository.(RedisOperationsSessionRepository.java:520) 
2018-09-17 02:20:49.804  WARN [nerContainer-44] s.s.d.r.RedisOperationsSessionRepository : Unable to publish SessionDestroyedEvent for session 06c49807-ab00-4369-b3f4-d45640adc6e3 at org.springframework.session.data.redis.RedisOperationsSessionRepository.(RedisOperationsSessionRepository.java:520) 
2018-09-17 02:20:50.420  WARN [nerContainer-45] s.s.d.r.RedisOperationsSessionRepository : Unable to publish SessionDestroyedEvent for session 7d808c10-f6b4-429d-b38f-b7f6fa17be63 at org.springframework.session.data.redis.RedisOperationsSessionRepository.(RedisOperationsSessionRepository.java:520) 
2018-09-17 02:20:56.221  WARN [nerContainer-49] s.s.d.r.RedisOperationsSessionRepository : Unable to publish SessionDestroyedEvent for session 2610eb7a-a8e5-484e-b722-eceadf2664e2 at org.springframework.session.data.redis.RedisOperationsSessionRepository.(RedisOperationsSessionRepository.java:520) 
2018-09-17 02:20:56.315  WARN [nerContainer-50] s.s.d.r.RedisOperationsSessionRepository : Unable to publish SessionDestroyedEvent for session a51bf928-a54c-4153-a4d8-4e8dde57bfdc at org.springframework.session.data.redis.RedisOperationsSessionRepository.(RedisOperationsSessionRepository.java:520) 
vpavic commented 6 years ago

Thanks for the report @pch851130 - as mentioned in #1029 (comment), please provide as much details as possible (exact versions you're using, relevant config) or, even better, a minimal, complete, and verifiable example that we can use to reproduce the problem.

pch851130 commented 6 years ago

I am using this version. The source code is too large to share.

pch851130 commented 6 years ago

@vpavic May I just ignore that message? What does that message mean? I have read the linked document below, but I do not know what it means. https://github.com/spring-projects/spring-session/issues/1029 https://github.com/spring-projects/spring-session/issues/1047

pch851130 commented 6 years ago

@vpavic warning occurs even though there is no code to reference the library. if add a library, get a warning. If remove a library, not get a warning.

vpavic commented 6 years ago

@pch851130 This message means that session record for which the event was raised was not present when event was handled. You can learn more about how RedisOperationsSessionRepository handles session expirations and events in the reference manual.

You shouldn't be ignoring these warning, as they suggest something is not right. We've had a few issues related to this, on top of the two issues you link also take a look a #499 and #1128.

warning occurs even though there is no code to reference the library.

If I understand correctly, you're having Spring Boot auto-configure Spring Session for you, and there is no explicit configuration of Spring Session involved? Is anything other interacting with this Redis instance? Are you perhaps using multiple Redis databases inside the same Redis instance (see #1128)?

The source code is too large to share.

Please understand that we need a way to reproduce this issue in order to be able to reliably fix it. Minimal, complete, and verifiable example is not about sharing your existing codebase but rather about creating a minimal sample that can be used to isolate and reproduce the problem.

vpavic commented 5 years ago

Closing due to lack of feedback. Please comment back if you can provide more details and we can re-open the issue.

habelson commented 2 years ago

I realize this issue is closed, and I cannot provide a minimum reproduceable example. But I can add more context. In my case, I am seeing this Warning come up in a microservice environment where many services are using redis for a shared session. It appears that when a session expires, the event triggers in all of the services. One of them wins and cleans up the session correctly and the rest of them log the warning message in the OP because the session is no longer found. At least in my case, I have been treating this as ignorable.

wash1983 commented 9 months ago

spring:session:sessions' Time-To-Live (TTL) should be set to be five minutes longer than the TTL of spring:session:sessions:expires. This ensures that when Redis notifications occur, the session can still be retrieved before it is fully invalidated. If both expire simultaneously, fetching a session would result in NULL and consequently trigger an error like 'Unable to publish SessionDestroyedEvent for session'. The reason for the inconsistency lies in the fact that org.springframework.session.data.redis.ReactiveRedisSessionRepository does not currently implement this specific TTL extension logic, unlike org.springframework.session.data.redis.RedisIndexedSessionRepository which calls org.springframework.session.data.redis.RedisSessionExpirationPolicy.onExpirationUpdated(Long, Session) to manage the TTL difference. In investigating the latest source code up to version 3.2.1, I've observed that ReactiveRedisSessionRepository still does not incorporate the same expiration management logic as RedisIndexedSessionRepository. This disparity could indeed cause issues in reactive web applications such as those using Spring Cloud Gateway. It would be desirable for ReactiveRedisSessionRepository to maintain consistent expiration policy behavior with RedisIndexedSessionRepository to prevent such occurrences. For your request phrased in English: "The TTL of spring:session:sessions ideally should be configured to be five minutes more than the TTL of spring:session:sessions:expires, ensuring that during Redis notifications, the session remains retrievable before being fully invalidated. If they expire concurrently, fetching the session would yield NULL, resulting in an error like 'Unable to publish SessionDestroyedEvent for session'. The reason for the TTLs not being different is due to org.springframework.session.data.redis.ReactiveRedisSessionRepository not currently implementing the TTL extension logic present in org.springframework.session.data.redis.RedisIndexedSessionRepository, which invokes org.springframework.session.data.redis.RedisSessionExpirationPolicy.onExpirationUpdated(Long, Session). Upon reviewing the most recent source code up until version 3.2.1, I noticed that ReactiveRedisSessionRepository still lacks this identical expiration management logic, potentially leading to problems in reactive web applications such as those built on Spring Cloud Gateway. It would be beneficial if ReactiveRedisSessionRepository implemented the same expiration policy consistency as RedisIndexedSessionRepository."

melooooooo commented 3 months ago

how to fix it