mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-11 20:03:58 +02:00
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
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user