mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-26 05:30:54 +03:00
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:
parent
2c3efc8106
commit
95e2d5beb8
5 changed files with 170 additions and 50 deletions
|
@ -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)
|
||||
|
|
10
lazy/once.go
10
lazy/once.go
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue