diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-10-30 11:15:15 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-10-30 12:18:29 +0100 |
commit | 729593c842794eaf7127050953a5c2256d332051 (patch) | |
tree | 5281780eca14f38571e00de021e0703a96b7f0d3 /hugolib | |
parent | e65268f2c2dd5ac54681d3266564901d99ed3ea3 (diff) |
hugolib: Fix deadlock when content building times out
Fixes #5375
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/hugo_sites_build_errors_test.go | 30 | ||||
-rw-r--r-- | hugolib/page.go | 11 |
2 files changed, 39 insertions, 2 deletions
diff --git a/hugolib/hugo_sites_build_errors_test.go b/hugolib/hugo_sites_build_errors_test.go index a5825b35f..3af596d7c 100644 --- a/hugolib/hugo_sites_build_errors_test.go +++ b/hugolib/hugo_sites_build_errors_test.go @@ -313,3 +313,33 @@ Some content. } } } + +// 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{}) + +} diff --git a/hugolib/page.go b/hugolib/page.go index f7149ad74..578aed9ed 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -290,10 +290,11 @@ func (p *Page) initContent() { 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 { @@ -301,6 +302,12 @@ func (p *Page) initContent() { return } + select { + case <-ctx.Done(): + return + default: + } + if len(p.summary) == 0 { if err = p.setAutoSummary(); err != nil { err = p.errorf(err, "failed to set auto summary") |