Skip to content

Commit 6e7d93b

Browse files
authored
fix(processor): correct error handling and annotations logic (#341)
Signed-off-by: chlins <[email protected]>
1 parent bc5518b commit 6e7d93b

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

pkg/backend/processor/base.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,13 @@ func (b *base) Process(ctx context.Context, builder build.Builder, workDir strin
131131
}
132132

133133
eg.Go(func() error {
134-
return retry.Do(func() error {
134+
select {
135+
case <-ctx.Done():
136+
return ctx.Err()
137+
default:
138+
}
139+
140+
if err := retry.Do(func() error {
135141
logrus.Debugf("processor: processing %s file %s", b.name, path)
136142

137143
desc, err := builder.BuildLayer(ctx, b.mediaType, workDir, path, hooks.NewHooks(
@@ -146,10 +152,7 @@ func (b *base) Process(ctx context.Context, builder build.Builder, workDir strin
146152
}),
147153
))
148154
if err != nil {
149-
err = fmt.Errorf("processor: failed to build layer for %s file %s: %w", b.name, path, err)
150-
logrus.Error(err)
151-
cancel()
152-
return err
155+
return fmt.Errorf("processor: failed to build layer for %s file %s: %w", b.name, path, err)
153156
}
154157

155158
logrus.Debugf("processor: successfully built %s layer for file %s [digest: %s, size: %d]", b.name, path, desc.Digest, desc.Size)
@@ -158,7 +161,15 @@ func (b *base) Process(ctx context.Context, builder build.Builder, workDir strin
158161
mu.Unlock()
159162

160163
return nil
161-
}, append(defaultRetryOpts, retry.Context(ctx))...)
164+
}, append(defaultRetryOpts, retry.Context(ctx))...); err != nil {
165+
logrus.Error(err)
166+
// Cancel manually to abort other tasks because if one fails,
167+
// we should abort all to avoid useless waiting.
168+
cancel()
169+
return err
170+
}
171+
172+
return nil
162173
})
163174
}
164175

@@ -180,10 +191,10 @@ func (b *base) Process(ctx context.Context, builder build.Builder, workDir strin
180191
}
181192

182193
if descriptors[j].Annotations != nil {
183-
if descriptors[i].Annotations[modelspec.AnnotationFilepath] != "" {
184-
pathJ = descriptors[i].Annotations[modelspec.AnnotationFilepath]
194+
if descriptors[j].Annotations[modelspec.AnnotationFilepath] != "" {
195+
pathJ = descriptors[j].Annotations[modelspec.AnnotationFilepath]
185196
} else {
186-
pathJ = descriptors[i].Annotations[legacymodelspec.AnnotationFilepath]
197+
pathJ = descriptors[j].Annotations[legacymodelspec.AnnotationFilepath]
187198
}
188199
}
189200

0 commit comments

Comments
 (0)