ref: 729593c842794eaf7127050953a5c2256d332051
parent: e65268f2c2dd5ac54681d3266564901d99ed3ea3
author: Bjørn Erik Pedersen <[email protected]>
date: Tue Oct 30 07:15:15 EDT 2018
hugolib: Fix deadlock when content building times out Fixes #5375
--- a/hugolib/hugo_sites_build_errors_test.go
+++ b/hugolib/hugo_sites_build_errors_test.go
@@ -313,3 +313,33 @@
}
}
}
+
+// https://github.com/gohugoio/hugo/issues/5375
+func TestSiteBuildTimeout(t *testing.T) {
+
+ b := newTestSitesBuilder(t)
+ b.WithConfigFile("toml", `
+timeout = 5
+`)
+
+ b.WithTemplatesAdded("_default/single.html", `
+{{ .WordCount }}
+`, "shortcodes/c.html", `
+{{ range .Page.Site.RegularPages }}
+{{ .WordCount }}
+{{ end }}
+
+`)
+
+ for i := 1; i < 100; i++ {
+ b.WithContent(fmt.Sprintf("page%d.md", i), `---
+title: "A page"
+---
+
+{{< c >}}`)
+
+ }
+
+ b.CreateSites().Build(BuildCfg{})
+
+}
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -290,15 +290,22 @@
defer cancel()
c := make(chan error, 1)
+ p.contentInitMu.Lock()
+ defer p.contentInitMu.Unlock()
+
go func() {
var err error
- p.contentInitMu.Lock()
- defer p.contentInitMu.Unlock()
err = p.prepareForRender()
if err != nil {
c <- err
return
+ }
+
+ select {
+ case <-ctx.Done():
+ return
+ default:
}
if len(p.summary) == 0 {