Skip to content

Commit 971d25e

Browse files
committed
fix: propagate context cancellation after Wait to prevent incomplete artifacts
Signed-off-by: Zhao Chen <winters.zc@antgroup.com>
1 parent f3fbdfe commit 971d25e

6 files changed

Lines changed: 19 additions & 0 deletions

File tree

pkg/backend/fetch.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ func (b *backend) Fetch(ctx context.Context, target string, cfg *config.Fetch) e
155155
}
156156

157157
_ = g.Wait()
158+
if ctx.Err() != nil {
159+
return fmt.Errorf("fetch cancelled: %w", ctx.Err())
160+
}
158161
if err := errors.Join(errs...); err != nil {
159162
return err
160163
}

pkg/backend/fetch_by_d7y.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ func (b *backend) fetchByDragonfly(ctx context.Context, target string, cfg *conf
155155
}
156156

157157
_ = g.Wait()
158+
if ctx.Err() != nil {
159+
return fmt.Errorf("fetch cancelled: %w", ctx.Err())
160+
}
158161
if err := errors.Join(errs...); err != nil {
159162
return err
160163
}

pkg/backend/processor/base.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ func (b *base) Process(ctx context.Context, builder build.Builder, workDir strin
191191

192192
_ = eg.Wait()
193193

194+
if ctx.Err() != nil {
195+
return nil, fmt.Errorf("processing cancelled: %w", ctx.Err())
196+
}
197+
194198
if err := errors.Join(errs...); err != nil {
195199
return nil, err
196200
}

pkg/backend/pull.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ func (b *backend) Pull(ctx context.Context, target string, cfg *config.Pull) err
150150
}
151151

152152
_ = g.Wait()
153+
if ctx.Err() != nil {
154+
return fmt.Errorf("pull cancelled: %w", ctx.Err())
155+
}
153156
if len(errs) > 0 {
154157
return fmt.Errorf("failed to pull blob to local: %w", errors.Join(errs...))
155158
}

pkg/backend/pull_by_d7y.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ func (b *backend) pullByDragonfly(ctx context.Context, target string, cfg *confi
131131
}
132132

133133
_ = g.Wait()
134+
if ctx.Err() != nil {
135+
return fmt.Errorf("pull cancelled: %w", ctx.Err())
136+
}
134137
if err := errors.Join(errs...); err != nil {
135138
return err
136139
}

pkg/backend/push.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ func (b *backend) Push(ctx context.Context, target string, cfg *config.Push) err
120120
}
121121

122122
g.Wait()
123+
if ctx.Err() != nil {
124+
return fmt.Errorf("push cancelled: %w", ctx.Err())
125+
}
123126
if len(errs) > 0 {
124127
return fmt.Errorf("failed to push blob to remote: %w", errors.Join(errs...))
125128
}

0 commit comments

Comments
 (0)