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 <derek@mcgstyle.net>
This commit is contained in:
parent
75771c4634
commit
c017e0efed
@ -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.
|
// 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 {
|
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 {
|
for _, desc := range descs {
|
||||||
desc := desc
|
desc := desc
|
||||||
|
|
||||||
@ -126,10 +126,11 @@ func Dispatch(ctx context.Context, handler Handler, limiter *semaphore.Weighted,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
eg.Go(func() error {
|
eg.Go(func() error {
|
||||||
desc := desc
|
desc := desc
|
||||||
|
|
||||||
children, err := handler.Handle(ctx, desc)
|
children, err := handler.Handle(ctx2, desc)
|
||||||
if limiter != nil {
|
if limiter != nil {
|
||||||
limiter.Release(1)
|
limiter.Release(1)
|
||||||
}
|
}
|
||||||
@ -141,7 +142,7 @@ func Dispatch(ctx context.Context, handler Handler, limiter *semaphore.Weighted,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(children) > 0 {
|
if len(children) > 0 {
|
||||||
return Dispatch(ctx, handler, limiter, children...)
|
return Dispatch(ctx2, handler, limiter, children...)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user