1
0
mirror of https://github.com/gofiber/fiber.git synced 2025-02-21 19:32:58 +00:00

Fix cache mutex lock (#1764)

This commit is contained in:
apoq 2022-02-11 09:48:52 +01:00 committed by GitHub
parent 505e4d77a7
commit b9efc76722
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -70,9 +70,8 @@ func New(config ...Config) fiber.Handler {
// Get entry from pool
e := manager.get(key)
// Lock entry and unlock when finished
// Lock entry
mux.Lock()
defer mux.Unlock()
// Get timestamp
ts := atomic.LoadUint64(&timestamp)
@ -105,15 +104,24 @@ func New(config ...Config) fiber.Handler {
c.Set(cfg.CacheHeader, cacheHit)
mux.Unlock()
// Return response
return nil
}
// make sure we're not blocking concurrent requests - do unlock
mux.Unlock()
// Continue stack, return err to Fiber if exist
if err := c.Next(); err != nil {
return err
}
// lock entry back and unlock on finish
mux.Lock()
defer mux.Unlock()
// Don't cache response if Next returns true
if cfg.Next != nil && cfg.Next(c) {
c.Set(cfg.CacheHeader, cacheUnreachable)