Skip to content

Commit defd16f

Browse files
committed
wip fix
1 parent fc3bb31 commit defd16f

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

internal/batches/executor/coordinator.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,14 @@ func (c *Coordinator) ExecuteAndBuildSpecs(ctx context.Context, batchSpec *batch
219219
c.exec.Start(ctx, tasks, ui)
220220
results, errs := c.exec.Wait()
221221

222+
// Create a copy of results to safely iterate over during cache operations
223+
resultsCopy := make([]taskResult, len(results))
224+
copy(resultsCopy, results)
225+
222226
// Write all step cache results to the cache.
223227
// Lock to protect cache operations from race conditions
224228
c.cacheMutex.Lock()
225-
for _, res := range results {
229+
for _, res := range resultsCopy {
226230
for _, stepRes := range res.stepResults {
227231
cacheKey := res.task.CacheKey(c.opts.GlobalEnv, c.opts.ExecOpts.WorkingDirectory, stepRes.StepIndex)
228232
if err := c.opts.Cache.Set(ctx, cacheKey, stepRes); err != nil {
@@ -236,7 +240,8 @@ func (c *Coordinator) ExecuteAndBuildSpecs(ctx context.Context, batchSpec *batch
236240
var specs []*batcheslib.ChangesetSpec
237241

238242
// Build ChangesetSpecs if possible and add to list.
239-
for _, taskResult := range results {
243+
// Using the copy of results to avoid race conditions
244+
for _, taskResult := range resultsCopy {
240245
// Don't build changeset specs for failed workspaces.
241246
if taskResult.err != nil {
242247
continue

internal/batches/executor/coordinator_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ func TestCoordinator_Execute(t *testing.T) {
341341

342342
// Run with a cold cache.
343343
t.Run("cold cache", func(t *testing.T) {
344+
t.Timeout(60 * time.Second) // Reduce timeout to 60 seconds to fail faster
344345
execute(t)
345346
verifyCache(t)
346347
})

0 commit comments

Comments
 (0)