1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-16 07:18:37 +00:00

When reading expired sessions - expire them (#12686) (#12690)

* When reading expired sessions - expire them

Update to latest macaron/session following merge of
https://gitea.com/macaron/session/pulls/11

Also remove old memory provider as 11 updates the memory provider to
make it unnecessary.

Signed-off-by: Andrew Thornton <art27@cantab.net>

* and macaron/session/pulls/12

Signed-off-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
techknowlogick
2020-09-02 18:51:56 -04:00
committed by GitHub
parent 87f02d90cf
commit 0e9dcc9500
9 changed files with 32 additions and 231 deletions

View File

@@ -96,6 +96,8 @@ type MemProvider struct {
// Init initializes memory session provider.
func (p *MemProvider) Init(maxLifetime int64, _ string) error {
p.lock.Lock()
p.list = list.New()
p.data = make(map[string]*list.Element)
p.maxLifetime = maxLifetime
p.lock.Unlock()
return nil
@@ -120,7 +122,8 @@ func (p *MemProvider) Read(sid string) (_ RawStore, err error) {
e, ok := p.data[sid]
p.lock.RUnlock()
if ok {
// Only restore if the session is still alive.
if ok && (e.Value.(*MemStore).lastAccess.Unix()+p.maxLifetime) >= time.Now().Unix() {
if err = p.update(sid); err != nil {
return nil, err
}
@@ -130,7 +133,10 @@ func (p *MemProvider) Read(sid string) (_ RawStore, err error) {
// Create a new session.
p.lock.Lock()
defer p.lock.Unlock()
if ok {
p.list.Remove(e)
delete(p.data, sid)
}
s := NewMemStore(sid)
p.data[sid] = p.list.PushBack(s)
return s, nil
@@ -213,5 +219,5 @@ func (p *MemProvider) GC() {
}
func init() {
Register("memory", &MemProvider{list: list.New(), data: make(map[string]*list.Element)})
Register("memory", &MemProvider{})
}