Skip to content

Commit a10c5ff

Browse files
authored
chore: protect build timings insert for invalid enums (#20821)
Database insert errors will fail the transaction. So this error is fatal. Properly return it for a better error call stack, and not just hiding the error in the logs.
1 parent f6556fc commit a10c5ff

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

coderd/provisionerdserver/provisionerdserver.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2175,6 +2175,12 @@ func (s *server) completeWorkspaceBuildJob(ctx context.Context, job database.Pro
21752175
continue
21762176
}
21772177

2178+
// Scan does not guarantee validity
2179+
if !stg.Valid() {
2180+
s.Logger.Warn(ctx, "invalid stage, will fail insert based one enum", slog.F("value", t.Stage))
2181+
continue
2182+
}
2183+
21782184
params.Stage = append(params.Stage, stg)
21792185
params.Source = append(params.Source, t.Source)
21802186
params.Resource = append(params.Resource, t.Resource)
@@ -2184,8 +2190,11 @@ func (s *server) completeWorkspaceBuildJob(ctx context.Context, job database.Pro
21842190
}
21852191
_, err = db.InsertProvisionerJobTimings(ctx, params)
21862192
if err != nil {
2187-
// Log error but don't fail the whole transaction for non-critical data
2193+
// A database error here will "fail" this transaction. Making this error fatal.
2194+
// If this error is seen, add checks above to validate the insert parameters. In
2195+
// production, timings should not be a fatal error.
21882196
s.Logger.Warn(ctx, "failed to update provisioner job timings", slog.F("job_id", jobID), slog.Error(err))
2197+
return xerrors.Errorf("update provisioner job timings: %w", err)
21892198
}
21902199

21912200
// On start, we want to ensure that workspace agents timeout statuses

0 commit comments

Comments
 (0)