diff options
author | Bjørn Erik Pedersen <[email protected]> | 2024-02-23 17:23:37 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2024-02-23 17:27:52 +0100 |
commit | 564bae06f6513cbca80bd54411f9a66ec2115995 (patch) | |
tree | 866e007d01590de2ec10023a9c3203b75be05841 | |
parent | bf14d0cb26df901cccea593dfefaabfdc42d01af (diff) | |
download | hugo-564bae06f6513cbca80bd54411f9a66ec2115995.tar.gz hugo-564bae06f6513cbca80bd54411f9a66ec2115995.zip |
cache/dynacache: Prevent multiple concurrent resizes
Updates #12129
-rw-r--r-- | cache/dynacache/dynacache.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/cache/dynacache/dynacache.go b/cache/dynacache/dynacache.go index 85b360138..0fd51590c 100644 --- a/cache/dynacache/dynacache.go +++ b/cache/dynacache/dynacache.go @@ -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() |