Skip to content

Commit

Permalink
Fix wg.Wait / error check out of order
Browse files Browse the repository at this point in the history
The loop starts a bunch of goroutines, so there's unlikely to be an error immediately. It needs to wait.

Not sure why I got this wrong lol
  • Loading branch information
DrJosh9000 committed Nov 1, 2023
1 parent 2c9640f commit efe883e
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions agent/artifact_uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,14 @@ func (a *ArtifactUploader) Collect(ctx context.Context) ([]*api.Artifact, error)
return nil, fmt.Errorf("getting working directory: %w", err)
}

var wg sync.WaitGroup

ac := &artifactCollector{
ArtifactUploader: a,
wd: wd,
seenPaths: make(map[string]bool),
}

wctx, cancel := context.WithCancelCause(ctx)
var wg sync.WaitGroup
for _, globPath := range strings.Split(a.conf.Paths, ArtifactPathDelimiter) {
globPath := strings.TrimSpace(globPath)
if globPath == "" {
Expand All @@ -140,13 +139,12 @@ func (a *ArtifactUploader) Collect(ctx context.Context) ([]*api.Artifact, error)
}
}()
}
wg.Wait()

if err := context.Cause(wctx); err != nil {
return nil, err
}

// Wait for workers to complete
wg.Wait()

return ac.artifacts, nil
}

Expand Down

0 comments on commit efe883e

Please sign in to comment.