From efe883efcc84aafab15c757d5673e8425a74852c Mon Sep 17 00:00:00 2001 From: Josh Deprez Date: Thu, 2 Nov 2023 09:31:57 +1100 Subject: [PATCH] Fix wg.Wait / error check out of order 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 --- agent/artifact_uploader.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/agent/artifact_uploader.go b/agent/artifact_uploader.go index 5687b0e90d..d612c0f2c2 100644 --- a/agent/artifact_uploader.go +++ b/agent/artifact_uploader.go @@ -116,8 +116,6 @@ 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, @@ -125,6 +123,7 @@ func (a *ArtifactUploader) Collect(ctx context.Context) ([]*api.Artifact, error) } wctx, cancel := context.WithCancelCause(ctx) + var wg sync.WaitGroup for _, globPath := range strings.Split(a.conf.Paths, ArtifactPathDelimiter) { globPath := strings.TrimSpace(globPath) if globPath == "" { @@ -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 }