Fix "stuck on build" in error situations in content processing
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 22 Dec 2021 18:00:32 +0000 (19:00 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 23 Dec 2021 14:09:27 +0000 (15:09 +0100)
Updates #8166

hugolib/pages_process.go

index 89a306a3bb51d4ded478cd5be7c33c2c6d1ce7c0..541c0ae3e4537ec05dba31e391e0b9c216967643 100644 (file)
@@ -115,17 +115,24 @@ type sitePagesProcessor struct {
        m           *pageMap
        errorSender herrors.ErrorSender
 
+       ctx       context.Context
        itemChan  chan interface{}
        itemGroup *errgroup.Group
 }
 
 func (p *sitePagesProcessor) Process(item interface{}) error {
-       p.itemChan <- item
+       select {
+       case <-p.ctx.Done():
+               return nil
+       default:
+               p.itemChan <- item
+       }
        return nil
 }
 
 func (p *sitePagesProcessor) Start(ctx context.Context) context.Context {
        p.itemGroup, ctx = errgroup.WithContext(ctx)
+       p.ctx = ctx
        p.itemGroup.Go(func() error {
                for item := range p.itemChan {
                        if err := p.doProcess(item); err != nil {