Skip to content

Commit

Permalink
fix: stepRun overwrite in requeue (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
abelanger5 authored Feb 27, 2024
1 parent 67d4c2a commit f05a25b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions internal/services/controllers/jobs/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,13 @@ func (ec *JobsControllerImpl) handleStepRunRequeue(ctx context.Context, task *ta

g := new(errgroup.Group)

for _, stepRun := range stepRuns {
stepRunCp := stepRun
for i := range stepRuns {
stepRunCp := stepRuns[i]

// wrap in func to get defer on the span to avoid leaking spans
g.Go(func() error {
var innerStepRun *db.StepRunModel

ctx, span := telemetry.NewSpan(ctx, "handle-step-run-requeue-step-run")
defer span.End()

Expand All @@ -527,7 +529,9 @@ func (ec *JobsControllerImpl) handleStepRunRequeue(ctx context.Context, task *ta
isTimedOut := !scheduleTimeoutAt.IsZero() && scheduleTimeoutAt.Before(now)

if isTimedOut {
stepRun, updateInfo, err := ec.repo.StepRun().UpdateStepRun(payload.TenantId, stepRunId, &repository.UpdateStepRunOpts{
var updateInfo *repository.StepRunUpdateInfo

innerStepRun, updateInfo, err = ec.repo.StepRun().UpdateStepRun(payload.TenantId, stepRunId, &repository.UpdateStepRunOpts{
CancelledAt: &now,
CancelledReason: repository.StringPtr("SCHEDULING_TIMED_OUT"),
Status: repository.StepRunStatusPtr(db.StepRunStatusCancelled),
Expand All @@ -537,7 +541,7 @@ func (ec *JobsControllerImpl) handleStepRunRequeue(ctx context.Context, task *ta
return fmt.Errorf("could not update step run %s: %w", stepRunId, err)
}

defer ec.handleStepRunUpdateInfo(stepRun, updateInfo)
defer ec.handleStepRunUpdateInfo(innerStepRun, updateInfo)

return nil
}
Expand Down

0 comments on commit f05a25b

Please sign in to comment.