Skip to content

fix: collect results after last error in ResultErrorPool#162

Open
Yanhu007 wants to merge 1 commit intosourcegraph:mainfrom
Yanhu007:fix/result-error-pool-clipped
Open

fix: collect results after last error in ResultErrorPool#162
Yanhu007 wants to merge 1 commit intosourcegraph:mainfrom
Yanhu007:fix/result-error-pool-clipped

Conversation

@Yanhu007
Copy link
Copy Markdown

Fixes #156

Problem

ResultErrorPool.Wait() drops all results that come after the last errored task:

p := pool.NewWithResults[int]().WithErrors().WithMaxGoroutines(1)
p.Go(func() (int, error) { return 1, nil })
p.Go(func() (int, error) { return 2, errors.New("err") })
p.Go(func() (int, error) { return 3, nil })

got, _ := p.Wait()
// Got:    [1]
// Expect: [1, 3]

The collect method's filtering loop appends segments between errored indices but never appends the tail segment after the last error.

Fix

Append the tail segment (results[lastErrored+1:]) after the loop.

Regression test added.

All existing tests pass.

The collect method in resultAggregator skipped all results that
came after the last errored task. The filtering loop only appended
segments between errored indices but never appended the tail
segment after the last error.

For example, with tasks [ok, err, ok], only the first ok was
returned instead of both ok results.

Add the tail segment after the loop. Add regression test.

Fixes sourcegraph#156
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Results clipped after first error with .WithErrors()

1 participant