From c017e0efed645b93cb3f6749f65212a45e104994 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Fri, 9 Aug 2019 15:48:29 -0700 Subject: [PATCH] Use a child context for errgroup in dispatch Prevent an errgroup error from causing the acquire to return a cancellation error. Previously any error from the errgroup would cause the Dispatch to always return the cancelled error. Signed-off-by: Derek McGowan --- images/handlers.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/images/handlers.go b/images/handlers.go index dac701bb8..04c2d5a60 100644 --- a/images/handlers.go +++ b/images/handlers.go @@ -117,7 +117,7 @@ func Walk(ctx context.Context, handler Handler, descs ...ocispec.Descriptor) err // // If any handler returns an error, the dispatch session will be canceled. func Dispatch(ctx context.Context, handler Handler, limiter *semaphore.Weighted, descs ...ocispec.Descriptor) error { - eg, ctx := errgroup.WithContext(ctx) + eg, ctx2 := errgroup.WithContext(ctx) for _, desc := range descs { desc := desc @@ -126,10 +126,11 @@ func Dispatch(ctx context.Context, handler Handler, limiter *semaphore.Weighted, return err } } + eg.Go(func() error { desc := desc - children, err := handler.Handle(ctx, desc) + children, err := handler.Handle(ctx2, desc) if limiter != nil { limiter.Release(1) } @@ -141,7 +142,7 @@ func Dispatch(ctx context.Context, handler Handler, limiter *semaphore.Weighted, } if len(children) > 0 { - return Dispatch(ctx, handler, limiter, children...) + return Dispatch(ctx2, handler, limiter, children...) } return nil