Fix concurrent map read and map write in short page lookups

Regression introduced in Hugo `v0.137.0`.

Fixes #13019
This commit is contained in:
Bjørn Erik Pedersen 2024-11-06 10:17:34 +01:00
parent 2c3efc8106
commit 95e2d5beb8
5 changed files with 170 additions and 50 deletions

View file

@ -36,7 +36,7 @@ type Init struct {
prev *Init
children []*Init
init OnceMore
init onceMore
out any
err error
f func(context.Context) (any, error)

View file

@ -24,13 +24,13 @@ import (
// * it can be reset, so the action can be repeated if needed
// * it has methods to check if it's done or in progress
type OnceMore struct {
type onceMore struct {
mu sync.Mutex
lock uint32
done uint32
}
func (t *OnceMore) Do(f func()) {
func (t *onceMore) Do(f func()) {
if atomic.LoadUint32(&t.done) == 1 {
return
}
@ -53,15 +53,15 @@ func (t *OnceMore) Do(f func()) {
f()
}
func (t *OnceMore) InProgress() bool {
func (t *onceMore) InProgress() bool {
return atomic.LoadUint32(&t.lock) == 1
}
func (t *OnceMore) Done() bool {
func (t *onceMore) Done() bool {
return atomic.LoadUint32(&t.done) == 1
}
func (t *OnceMore) ResetWithLock() *sync.Mutex {
func (t *onceMore) ResetWithLock() *sync.Mutex {
t.mu.Lock()
defer atomic.StoreUint32(&t.done, 0)
return &t.mu