spring-projects / spring-projects/spring-session

Delay in processing spring expiration events

Open
#3,396 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
Im running into a weird problem. I have the spring session redis thread executor as below
@Bean(name = "springSessionRedisTaskExecutor") public TaskExecutor springSessionRedisTaskExecutor() { ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); taskExecutor.setThreadNamePrefix("someuniquename"); taskExecutor.setMaxPoolSize(10); taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy()); return taskExecutor; }

I can see in my application logs that there are frequent error logs with message
Unable to publish SessionDestroyedEvent for session someid

To debug I took the minutebased cronjob redis key and checked the session id's which are supposed to execute at the next minute. After that when I was verifying how many of those session's have been actually expired I found that from 600 around 30 session's haven't expired yet (i.e didnt get the event as we have one more method based on this session destroyed event). And what is more weird is that Im getting that Unable to publish SessionDestroyedEvent log message for these sessions at a later point of time anywhere between few hours to few days. To check if redis is delaying from sending expired event I connected to the expired channel to check if all expired events for the session ids are being pushed. That is working correctly however there seems to be some unexpected lag when consuming these events at spring side. I'm not able to figure out the problem, can someone provide me pointers on what to check or has anyone else faced the same issue>

To Reproduce
Kill around 3k sessions at a single point of time

Expected behavior
Every session should be cleared, but few sessions are getting cleared in huge delay

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 by tracing the springSessionRedisTaskExecutor configuration and the path from the Redis expired channel to SessionDestroyedEvent publication. Reproduce the issue by killing around 3,000 sessions at once, then compare the minute-based cronjob Redis keys, published expiration events, and application logs. Done means the delayed or missing session destruction events are explained and the expected behavior is verified.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, redis, spring
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.