summaryrefslogtreecommitdiffstats
path: root/lazy/init.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-03-04 18:08:29 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-03-04 21:29:05 +0100
commit3bbeb5688c4452a336af07be1e8cec44dac7d6ce (patch)
treef7e9f79839d1c050c148b5265c066f98a088fa8a /lazy/init.go
parent184a67ac4704b88083c43a68a5f85800192d7ff1 (diff)
Fix "context canceled" with partial
Make sure the context used for timeouts isn't created based on the incoming context, as we have cases where this can cancel the context prematurely. Fixes #10789
Diffstat (limited to 'lazy/init.go')
-rw-r--r--lazy/init.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/lazy/init.go b/lazy/init.go
index 4de2a83f7..bfb9c4e07 100644
--- a/lazy/init.go
+++ b/lazy/init.go
@@ -180,14 +180,15 @@ func (ini *Init) checkDone() {
}
func (ini *Init) withTimeout(ctx context.Context, timeout time.Duration, f func(ctx context.Context) (any, error)) (any, error) {
- ctx, cancel := context.WithTimeout(ctx, timeout)
+ // Create a new context with a timeout not connected to the incoming context.
+ waitCtx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
c := make(chan verr, 1)
go func() {
v, err := f(ctx)
select {
- case <-ctx.Done():
+ case <-waitCtx.Done():
return
default:
c <- verr{v: v, err: err}
@@ -195,7 +196,7 @@ func (ini *Init) withTimeout(ctx context.Context, timeout time.Duration, f func(
}()
select {
- case <-ctx.Done():
+ case <-waitCtx.Done():
return nil, errors.New("timed out initializing value. You may have a circular loop in a shortcode, or your site may have resources that take longer to build than the `timeout` limit in your Hugo config file.")
case ve := <-c:
return ve.v, ve.err