aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2024-10-26 15:36:02 +0200
committerBjørn Erik Pedersen <[email protected]>2024-10-26 18:27:10 +0200
commite10915f80af18cbe24b0f5e22922b87ce0bc74ae (patch)
treed0a13804e0e4ac1057c4d03f7202d938f11d50e0
parentec3890affe55af1fa196901f446cc0e7df059da8 (diff)
downloadhugo-e10915f80af18cbe24b0f5e22922b87ce0bc74ae.tar.gz
hugo-e10915f80af18cbe24b0f5e22922b87ce0bc74ae.zip
dynacache: Fix potential deadlocks on panics in GetOrCreate
-rw-r--r--cache/dynacache/dynacache_test.go25
-rw-r--r--go.mod2
-rw-r--r--go.sum2
3 files changed, 28 insertions, 1 deletions
diff --git a/cache/dynacache/dynacache_test.go b/cache/dynacache/dynacache_test.go
index a58a8d94b..9a932729b 100644
--- a/cache/dynacache/dynacache_test.go
+++ b/cache/dynacache/dynacache_test.go
@@ -14,8 +14,10 @@
package dynacache
import (
+ "fmt"
"path/filepath"
"testing"
+ "time"
qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/common/loggers"
@@ -165,6 +167,29 @@ func TestClear(t *testing.T) {
cache.adjustCurrentMaxSize()
}
+func TestPanicInCreate(t *testing.T) {
+ t.Parallel()
+ c := qt.New(t)
+ cache := newTestCache(t)
+
+ p1 := GetOrCreatePartition[string, testItem](cache, "/aaaa/bbbb", OptionsPartition{Weight: 30, ClearWhen: ClearOnRebuild})
+
+ for i := 0; i < 3; i++ {
+ for j := 0; j < 3; j++ {
+ _, err := p1.GetOrCreate(fmt.Sprintf("panic1-%d", i), func(string) (testItem, error) {
+ panic("failed")
+ })
+
+ c.Assert(err, qt.Not(qt.IsNil))
+
+ _, err = p1.GetOrCreateWitTimeout(fmt.Sprintf("panic2-%d", i), 10*time.Second, func(string) (testItem, error) {
+ panic("failed")
+ })
+ c.Assert(err, qt.Not(qt.IsNil))
+ }
+ }
+}
+
func TestAdjustCurrentMaxSize(t *testing.T) {
t.Parallel()
c := qt.New(t)
diff --git a/go.mod b/go.mod
index 392119e17..3f5d4a707 100644
--- a/go.mod
+++ b/go.mod
@@ -16,7 +16,7 @@ require (
github.com/bep/gowebp v0.3.0
github.com/bep/helpers v0.5.0
github.com/bep/imagemeta v0.8.1
- github.com/bep/lazycache v0.4.0
+ github.com/bep/lazycache v0.6.0
github.com/bep/logg v0.4.0
github.com/bep/mclib v1.20400.20402
github.com/bep/overlayfs v0.9.2
diff --git a/go.sum b/go.sum
index 6f3e61e89..6346fb099 100644
--- a/go.sum
+++ b/go.sum
@@ -143,6 +143,8 @@ github.com/bep/imagemeta v0.8.1 h1:tjZLPRftjxU7PTI87o5e5WKOFQ4S9S0engiP1OTpJTI=
github.com/bep/imagemeta v0.8.1/go.mod h1:5piPAq5Qomh07m/dPPCLN3mDJyFusvUG7VwdRD/vX0s=
github.com/bep/lazycache v0.4.0 h1:X8yVyWNVupPd4e1jV7efi3zb7ZV/qcjKQgIQ5aPbkYI=
github.com/bep/lazycache v0.4.0/go.mod h1:NmRm7Dexh3pmR1EignYR8PjO2cWybFQ68+QgY3VMCSc=
+github.com/bep/lazycache v0.6.0 h1:0vCgFo7TBtMQpSx64jnH1sagmw0ZougIFRpsqPHTa5U=
+github.com/bep/lazycache v0.6.0/go.mod h1:NmRm7Dexh3pmR1EignYR8PjO2cWybFQ68+QgY3VMCSc=
github.com/bep/logg v0.4.0 h1:luAo5mO4ZkhA5M1iDVDqDqnBBnlHjmtZF6VAyTp+nCQ=
github.com/bep/logg v0.4.0/go.mod h1:Ccp9yP3wbR1mm++Kpxet91hAZBEQgmWgFgnXX3GkIV0=
github.com/bep/mclib v1.20400.20402 h1:olpCE2WSPpOAbFE1R4hnftSEmQ34+xzy2HRzd0m69rA=