1
0
mirror of https://github.com/gohugoio/hugo.git synced 2024-05-11 05:54:58 +00:00

hugolib: Fix freeze in invalid front matter error case

Fixes #4526
This commit is contained in:
Bjørn Erik Pedersen
2018-03-24 09:19:49 +01:00
parent e9c7b6205f
commit 93e24a03ce
4 changed files with 95 additions and 14 deletions

View File

@@ -32,6 +32,8 @@ type siteContentProcessor struct {
handleContent contentHandler
ctx context.Context
// The input file bundles.
fileBundlesChan chan *bundleDir
@@ -51,7 +53,28 @@ type siteContentProcessor struct {
partialBuild bool
}
func newSiteContentProcessor(baseDir string, partialBuild bool, s *Site) *siteContentProcessor {
func (s *siteContentProcessor) processBundle(b *bundleDir) {
select {
case s.fileBundlesChan <- b:
case <-s.ctx.Done():
}
}
func (s *siteContentProcessor) processSingle(fi *fileInfo) {
select {
case s.fileSinglesChan <- fi:
case <-s.ctx.Done():
}
}
func (s *siteContentProcessor) processAssets(assets []string) {
select {
case s.fileAssetsChan <- assets:
case <-s.ctx.Done():
}
}
func newSiteContentProcessor(ctx context.Context, baseDir string, partialBuild bool, s *Site) *siteContentProcessor {
numWorkers := 12
if n := runtime.NumCPU() * 3; n > numWorkers {
numWorkers = n
@@ -60,6 +83,7 @@ func newSiteContentProcessor(baseDir string, partialBuild bool, s *Site) *siteCo
numWorkers = int(math.Ceil(float64(numWorkers) / float64(len(s.owner.Sites))))
return &siteContentProcessor{
ctx: ctx,
partialBuild: partialBuild,
baseDir: baseDir,
site: s,
@@ -80,7 +104,7 @@ func (s *siteContentProcessor) closeInput() {
func (s *siteContentProcessor) process(ctx context.Context) error {
g1, ctx := errgroup.WithContext(ctx)
g2, _ := errgroup.WithContext(ctx)
g2, ctx := errgroup.WithContext(ctx)
// There can be only one of these per site.
g1.Go(func() error {
@@ -161,12 +185,14 @@ func (s *siteContentProcessor) process(ctx context.Context) error {
})
}
if err := g2.Wait(); err != nil {
return err
}
err := g2.Wait()
close(s.pagesChan)
if err != nil {
return err
}
if err := g1.Wait(); err != nil {
return err
}