Commit aa4b2f0
Prevent re-adding deleted sessions to Redis principal index
RedisSession#saveDelta() unconditionally re-adds the session id to the
resolved principal's index set whenever the delta contains the
principal/security-context attribute key. RedisIndexedSessionRepository
#deleteById() first removes the session id via cleanupPrincipalIndex(),
then sets maxInactiveInterval to Duration.ZERO and calls save(session),
which invokes saveDelta().
Under SaveMode.ALWAYS, the RedisSession constructor unconditionally
copies every current attribute (including the principal-index
attribute) into the delta, so saveDelta() always takes the
principal-index branch on this path. Since the session's own
attributes are untouched by deleteById(), resolveIndexesFor() still
resolves the same principal, and saveDelta() re-adds the id to the
index set that cleanupPrincipalIndex() had just removed it from. The
principal's Redis set (e.g. "spring:session:index:...:<principal>")
then keeps growing with ids of sessions that were explicitly
invalidated, leaking memory.
Guard the re-add with RedisSession#isExpired(), which is already true
at this point in deleteById() (maxInactiveInterval is set to Duration
.ZERO, not a negative "never expires" value). The unconditional removal
of the id from the previous principal's set is left untouched, since
removal is always correct regardless of expiration state.
Closes gh-1843
Signed-off-by: seonwoo_jung <79202163+seonwooj0810@users.noreply.github.com>1 parent 01e06a4 commit aa4b2f0
2 files changed
Lines changed: 26 additions & 1 deletion
File tree
- spring-session-data-redis/src
- main/java/org/springframework/session/data/redis
- test/java/org/springframework/session/data/redis
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
913 | 913 | | |
914 | 914 | | |
915 | 915 | | |
916 | | - | |
| 916 | + | |
917 | 917 | | |
918 | 918 | | |
919 | 919 | | |
| |||
Lines changed: 25 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
334 | 334 | | |
335 | 335 | | |
336 | 336 | | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
337 | 362 | | |
338 | 363 | | |
339 | 364 | | |
| |||
0 commit comments