Skip to content

Commit c017e0e

Browse files
committed
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 <[email protected]>
1 parent 75771c4 commit c017e0e

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

images/handlers.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func Walk(ctx context.Context, handler Handler, descs ...ocispec.Descriptor) err
117117
//
118118
// If any handler returns an error, the dispatch session will be canceled.
119119
func Dispatch(ctx context.Context, handler Handler, limiter *semaphore.Weighted, descs ...ocispec.Descriptor) error {
120-
eg, ctx := errgroup.WithContext(ctx)
120+
eg, ctx2 := errgroup.WithContext(ctx)
121121
for _, desc := range descs {
122122
desc := desc
123123

@@ -126,10 +126,11 @@ func Dispatch(ctx context.Context, handler Handler, limiter *semaphore.Weighted,
126126
return err
127127
}
128128
}
129+
129130
eg.Go(func() error {
130131
desc := desc
131132

132-
children, err := handler.Handle(ctx, desc)
133+
children, err := handler.Handle(ctx2, desc)
133134
if limiter != nil {
134135
limiter.Release(1)
135136
}
@@ -141,7 +142,7 @@ func Dispatch(ctx context.Context, handler Handler, limiter *semaphore.Weighted,
141142
}
142143

143144
if len(children) > 0 {
144-
return Dispatch(ctx, handler, limiter, children...)
145+
return Dispatch(ctx2, handler, limiter, children...)
145146
}
146147

147148
return nil

0 commit comments

Comments
 (0)