Skip to content

Commit 450d496

Browse files
committed
fix: use buildCtx for image wait and recalculate duration
Addresses PR review feedback: 1. Use buildCtx instead of ctx for waitForImageReady to respect build timeout during image conversion wait 2. Recalculate duration after waitForImageReady completes to accurately report total build time including image conversion
1 parent 3180b1d commit 450d496

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

lib/builds/manager.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,16 +301,24 @@ func (m *manager) runBuild(ctx context.Context, id string, req CreateBuildReques
301301
// Wait for image to be ready before reporting build as complete.
302302
// This fixes the race condition (KERNEL-863) where build reports "ready"
303303
// but image conversion hasn't finished yet.
304-
if err := m.waitForImageReady(ctx, id); err != nil {
304+
// Use buildCtx to respect the build timeout during image wait.
305+
if err := m.waitForImageReady(buildCtx, id); err != nil {
306+
// Recalculate duration to include image wait time
307+
duration = time.Since(start)
308+
durationMS = duration.Milliseconds()
305309
m.logger.Error("image conversion failed after build", "id", id, "error", err, "duration", duration)
306310
errMsg := fmt.Sprintf("image conversion failed: %v", err)
307311
m.updateBuildComplete(id, StatusFailed, nil, &errMsg, &result.Provenance, &durationMS)
308312
if m.metrics != nil {
309-
m.metrics.RecordBuild(ctx, "failed", duration)
313+
m.metrics.RecordBuild(buildCtx, "failed", duration)
310314
}
311315
return
312316
}
313317

318+
// Recalculate duration to include image wait time for accurate reporting
319+
duration = time.Since(start)
320+
durationMS = duration.Milliseconds()
321+
314322
m.updateBuildComplete(id, StatusReady, &result.ImageDigest, nil, &result.Provenance, &durationMS)
315323

316324
// Update with image ref
@@ -320,7 +328,7 @@ func (m *manager) runBuild(ctx context.Context, id string, req CreateBuildReques
320328
}
321329

322330
if m.metrics != nil {
323-
m.metrics.RecordBuild(ctx, "success", duration)
331+
m.metrics.RecordBuild(buildCtx, "success", duration)
324332
}
325333
}
326334

0 commit comments

Comments
 (0)