Skip to content

Commit 95ce2a4

Browse files
committed
hugolib: Prevent parallel server rebuilds
There have been reports about infrequent paginator crashes when running the Hugo server since 0.55.0. The reason have been narrowed down to that of parallel rebuilds. This isn't a new thing, but the changes in 0.55.0 made it extra important to serialize the page initialization. This commit fixes that by protecting the `Build` method with a lock when running in server mode. Fixes gohugoio#5885 Fixes gohugoio#5968
1 parent a83256b commit 95ce2a4

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

‎hugolib/hugo_sites.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ type HugoSites struct {
6262
// If this is running in the dev server.
6363
running bool
6464

65+
// Serializes rebuilds when server is running.
66+
runningMu sync.Mutex
67+
6568
// Render output formats for all sites.
6669
renderFormats output.Formats
6770

‎hugolib/hugo_sites_build.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ import (
3131
// Build builds all sites. If filesystem events are provided,
3232
// this is considered to be a potential partial rebuild.
3333
func (h *HugoSites) Build(config BuildCfg, events ...fsnotify.Event) error {
34+
if h.running {
35+
// Make sure we don't trigger rebuilds in parallel.
36+
h.runningMu.Lock()
37+
defer h.runningMu.Unlock()
38+
}
39+
3440
ctx, task := trace.NewTask(context.Background(), "Build")
3541
defer task.End()
3642

0 commit comments

Comments
 (0)