Remove session expiration timer
This commit is contained in:
parent
c49bbc72d4
commit
494dbc4cf5
@ -20,7 +20,6 @@ type Session struct {
|
||||
|
||||
key string
|
||||
createdAt int64
|
||||
expiration *time.Timer
|
||||
lock sync.Mutex
|
||||
}
|
||||
|
||||
@ -34,15 +33,9 @@ func New(id uint64) (*Session, error) {
|
||||
key: key,
|
||||
createdAt: time.Now().Unix(),
|
||||
UserID: id,
|
||||
expiration: time.NewTimer(Expiration),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Session) Init() {
|
||||
exp := time.Until(time.Unix(s.createdAt, 0).Add(Expiration))
|
||||
s.expiration = time.NewTimer(exp)
|
||||
}
|
||||
|
||||
func (s *Session) Key() string {
|
||||
s.lock.Lock()
|
||||
key := s.key
|
||||
@ -51,11 +44,15 @@ func (s *Session) Key() string {
|
||||
}
|
||||
|
||||
func (s *Session) SetCookie(w http.ResponseWriter, r *http.Request) {
|
||||
s.lock.Lock()
|
||||
created := time.Unix(s.createdAt, 0)
|
||||
s.lock.Unlock()
|
||||
|
||||
http.SetCookie(w, &http.Cookie{
|
||||
Name: CookieName,
|
||||
Value: s.Key(),
|
||||
Path: "/",
|
||||
Expires: time.Now().Add(Expiration),
|
||||
Expires: created.Add(Expiration),
|
||||
HttpOnly: true,
|
||||
Secure: r.TLS != nil,
|
||||
})
|
||||
@ -83,8 +80,6 @@ func (s *Session) Refresh() (string, bool, error) {
|
||||
return "", false, err
|
||||
}
|
||||
|
||||
s.expiration.Reset(Expiration)
|
||||
|
||||
s.lock.Lock()
|
||||
s.createdAt = time.Now().Unix()
|
||||
s.key = key
|
||||
@ -95,10 +90,6 @@ func (s *Session) Refresh() (string, bool, error) {
|
||||
return "", false, nil
|
||||
}
|
||||
|
||||
func (s *Session) WaitUntilExpiration() {
|
||||
<-s.expiration.C
|
||||
}
|
||||
|
||||
func newSessionKey() (string, error) {
|
||||
key := make([]byte, 32)
|
||||
_, err := rand.Read(key)
|
||||
|
@ -248,7 +248,6 @@ func newStateStore(sessionStore storage.SessionStore) *stateStore {
|
||||
|
||||
for _, session := range sessions {
|
||||
if !session.Expired() {
|
||||
session.Init()
|
||||
store.sessions[session.Key()] = session
|
||||
} else {
|
||||
go sessionStore.DeleteSession(session.Key())
|
||||
|
Loading…
Reference in New Issue
Block a user