aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-04-08 00:11:24 +0800
committerGitHub <noreply@github.com>2023-04-07 18:11:24 +0200
commit97d5ec2aeb4a3718a5f27aa4ad608e1a0e3a94b4 (patch)
treef45cd2c0937520333a29c4cf27d74558ad3811a9 /modules
parent26a0cd7143cc933cee37ac87696eeda46b1ea437 (diff)
downloadgitea-97d5ec2aeb4a3718a5f27aa4ad608e1a0e3a94b4.tar.gz
gitea-97d5ec2aeb4a3718a5f27aa4ad608e1a0e3a94b4.zip
Use Get/Set instead of Rename when Regenerate session id (#23975)
Do not use Rename here, because the old sid and new sid may be in different redis cluster slot. Fix #23869
Diffstat (limited to 'modules')
-rw-r--r--modules/session/redis.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/modules/session/redis.go b/modules/session/redis.go
index 5fb59e4804..b7cdbef6f8 100644
--- a/modules/session/redis.go
+++ b/modules/session/redis.go
@@ -183,16 +183,21 @@ func (p *RedisProvider) Regenerate(oldsid, sid string) (_ session.RawStore, err
}
}
- if err = p.c.Rename(graceful.GetManager().HammerContext(), poldsid, psid).Err(); err != nil {
+ // do not use Rename here, because the old sid and new sid may be in different redis cluster slot.
+ kvs, err := p.c.Get(graceful.GetManager().HammerContext(), poldsid).Result()
+ if err != nil {
return nil, err
}
- var kv map[interface{}]interface{}
- kvs, err := p.c.Get(graceful.GetManager().HammerContext(), psid).Result()
- if err != nil {
+ if err = p.c.Del(graceful.GetManager().HammerContext(), poldsid).Err(); err != nil {
return nil, err
}
+ if err = p.c.Set(graceful.GetManager().HammerContext(), psid, kvs, p.duration).Err(); err != nil {
+ return nil, err
+ }
+
+ var kv map[interface{}]interface{}
if len(kvs) == 0 {
kv = make(map[interface{}]interface{})
} else {