aboutsummaryrefslogtreecommitdiffhomepage
path: root/hugolib/hugo_sites_build.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2019-05-18 08:38:58 +0200
committerBjørn Erik Pedersen <[email protected]>2019-05-18 09:01:40 +0200
commit95ce2a40e734bb82b69f9a64270faf3ed69c92cc (patch)
tree3391ca7d88672042ae5e2ef8f764797cbc381325 /hugolib/hugo_sites_build.go
parenta83256b9cd5c50dde1a086a48f365a1fcbc78a24 (diff)
downloadhugo-95ce2a40e734bb82b69f9a64270faf3ed69c92cc.tar.gz
hugo-95ce2a40e734bb82b69f9a64270faf3ed69c92cc.zip
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 #5885 Fixes #5968
Diffstat (limited to 'hugolib/hugo_sites_build.go')
-rw-r--r--hugolib/hugo_sites_build.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/hugolib/hugo_sites_build.go b/hugolib/hugo_sites_build.go
index d748a0169..7f725def2 100644
--- a/hugolib/hugo_sites_build.go
+++ b/hugolib/hugo_sites_build.go
@@ -31,6 +31,12 @@ import (
// Build builds all sites. If filesystem events are provided,
// this is considered to be a potential partial rebuild.
func (h *HugoSites) Build(config BuildCfg, events ...fsnotify.Event) error {
+ if h.running {
+ // Make sure we don't trigger rebuilds in parallel.
+ h.runningMu.Lock()
+ defer h.runningMu.Unlock()
+ }
+
ctx, task := trace.NewTask(context.Background(), "Build")
defer task.End()