mirror of
https://github.com/gofiber/fiber.git
synced 2025-05-31 11:52:41 +00:00
🐛 fix: even error we gonna to unlock it, else it will went deadlock (#1248)
This commit is contained in:
parent
ca0e784fb9
commit
c71da35ddb
@ -142,12 +142,12 @@ func (s *Session) Save() error {
|
|||||||
|
|
||||||
// Convert data to bytes
|
// Convert data to bytes
|
||||||
mux.Lock()
|
mux.Lock()
|
||||||
|
defer mux.Unlock()
|
||||||
encCache := gob.NewEncoder(s.byteBuffer)
|
encCache := gob.NewEncoder(s.byteBuffer)
|
||||||
err := encCache.Encode(&s.data.Data)
|
err := encCache.Encode(&s.data.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
mux.Unlock()
|
|
||||||
|
|
||||||
// pass raw bytes with session id to provider
|
// pass raw bytes with session id to provider
|
||||||
if err := s.config.Storage.Set(s.id, s.byteBuffer.Bytes(), s.config.Expiration); err != nil {
|
if err := s.config.Storage.Set(s.id, s.byteBuffer.Bytes(), s.config.Expiration); err != nil {
|
||||||
|
@ -70,13 +70,13 @@ func (s *Store) Get(c *fiber.Ctx) (*Session, error) {
|
|||||||
// Unmashal if we found data
|
// Unmashal if we found data
|
||||||
if raw != nil && err == nil {
|
if raw != nil && err == nil {
|
||||||
mux.Lock()
|
mux.Lock()
|
||||||
|
defer mux.Unlock()
|
||||||
_, _ = sess.byteBuffer.Write(raw)
|
_, _ = sess.byteBuffer.Write(raw)
|
||||||
encCache := gob.NewDecoder(sess.byteBuffer)
|
encCache := gob.NewDecoder(sess.byteBuffer)
|
||||||
err := encCache.Decode(&sess.data.Data)
|
err := encCache.Decode(&sess.data.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
mux.Unlock()
|
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
@ -95,6 +95,7 @@ func (s *Store) responseCookies(c *fiber.Ctx) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cookie := fasthttp.AcquireCookie()
|
cookie := fasthttp.AcquireCookie()
|
||||||
|
defer fasthttp.ReleaseCookie(cookie)
|
||||||
err := cookie.ParseBytes(cookieValue)
|
err := cookie.ParseBytes(cookieValue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -103,7 +104,6 @@ func (s *Store) responseCookies(c *fiber.Ctx) (string, error) {
|
|||||||
value := make([]byte, len(cookie.Value()))
|
value := make([]byte, len(cookie.Value()))
|
||||||
copy(value, cookie.Value())
|
copy(value, cookie.Value())
|
||||||
id := utils.UnsafeString(value)
|
id := utils.UnsafeString(value)
|
||||||
fasthttp.ReleaseCookie(cookie)
|
|
||||||
return id, nil
|
return id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user