Skip to content

Commit

Permalink
hugolib: Prevent parallel server rebuilds
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bep committed May 18, 2019
1 parent a83256b commit 95ce2a4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions hugolib/hugo_sites.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ type HugoSites struct {
// If this is running in the dev server.
running bool

// Serializes rebuilds when server is running.
runningMu sync.Mutex

// Render output formats for all sites.
renderFormats output.Formats

Expand Down
6 changes: 6 additions & 0 deletions hugolib/hugo_sites_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 95ce2a4

Please sign in to comment.