🐛 fix: even error we gonna to unlock it, else it will went deadlock (#1248)

pull/1251/head
SianLoong 2021-03-31 05:40:09 +08:00 committed by GitHub
parent ca0e784fb9
commit c71da35ddb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -142,12 +142,12 @@ func (s *Session) Save() error {
// Convert data to bytes
mux.Lock()
defer mux.Unlock()
encCache := gob.NewEncoder(s.byteBuffer)
err := encCache.Encode(&s.data.Data)
if err != nil {
return err
}
mux.Unlock()
// pass raw bytes with session id to provider
if err := s.config.Storage.Set(s.id, s.byteBuffer.Bytes(), s.config.Expiration); err != nil {

View File

@ -70,13 +70,13 @@ func (s *Store) Get(c *fiber.Ctx) (*Session, error) {
// Unmashal if we found data
if raw != nil && err == nil {
mux.Lock()
defer mux.Unlock()
_, _ = sess.byteBuffer.Write(raw)
encCache := gob.NewDecoder(sess.byteBuffer)
err := encCache.Decode(&sess.data.Data)
if err != nil {
return nil, err
}
mux.Unlock()
} else if err != nil {
return nil, err
} else {
@ -95,6 +95,7 @@ func (s *Store) responseCookies(c *fiber.Ctx) (string, error) {
}
cookie := fasthttp.AcquireCookie()
defer fasthttp.ReleaseCookie(cookie)
err := cookie.ParseBytes(cookieValue)
if err != nil {
return "", err
@ -103,7 +104,6 @@ func (s *Store) responseCookies(c *fiber.Ctx) (string, error) {
value := make([]byte, len(cookie.Value()))
copy(value, cookie.Value())
id := utils.UnsafeString(value)
fasthttp.ReleaseCookie(cookie)
return id, nil
}