]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
cache/dynacache: Prevent multiple concurrent resizes
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 23 Feb 2024 16:23:37 +0000 (17:23 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 23 Feb 2024 16:27:52 +0000 (17:27 +0100)
Updates #12129

cache/dynacache/dynacache.go

index 85b36013867e7264ef40c995c3f8be7ad89b9777..0fd51590cc8b33b0fc4aed4b7072b7e63cc07abe 100644 (file)
@@ -119,7 +119,8 @@ func (o OptionsPartition) CalculateMaxSize(maxSizePerPartition int) int {
 
 // A dynamic partitioned cache.
 type Cache struct {
-       mu sync.RWMutex
+       mu       sync.RWMutex
+       resizeMu sync.Mutex
 
        partitions map[string]PartitionManager
 
@@ -231,6 +232,12 @@ func (c *Cache) Stop() {
 }
 
 func (c *Cache) adjustCurrentMaxSize() {
+       if !c.resizeMu.TryLock() {
+               // Prevent multiple concurrent resizes.
+               return
+       }
+       defer c.resizeMu.Unlock()
+
        c.mu.RLock()
        defer c.mu.RUnlock()