-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Closed
Labels
DocumentationIssues describing a change to documentation.Issues describing a change to documentation.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.help wanted
Milestone
Description
What version of Go are you using (go version)?
go version go1.19-pre4 cl/455575533 +12f49fe0ed linux/amd64
Does this issue reproduce with the latest release?
Yes
What did you do?
package test
import (
"errors"
"sync/atomic"
"testing"
"time"
"golang.org/x/sync/errgroup"
)
func TestErrGroupDoesNotRunNewFunctionsAfterPreviousError(t *testing.T) {
group := errgroup.Group{}
group.SetLimit(1)
group.Go(func() error {
return errors.New("")
})
time.Sleep(time.Second)
var ran atomic.Bool
group.Go(func() error {
ran.Store(true)
return nil
})
_ = group.Wait()
if ran.Load() {
t.Errorf("Expected second func not to run, but it did")
}
}
What did you expect to see?
The documentation for errgroup states:
Go calls the given function in a new goroutine. It blocks until the new goroutine can be added without the number of active goroutines in the group exceeding the configured limit.
The first call to return a non-nil error cancels the group; its error will be returned by Wait.
I would assume that if the first call to return a non-nil error cancels the group, future funcs passed to go won't run.
Furthermore calls to group.Wait() should return immediately rather than waiting for funcs created after the group was cancelled to complete.
What did you see instead?
All funcs are called, even those created after the group was cancelled. group.Wait() waits for all funcs to complete before returning.
Metadata
Metadata
Assignees
Labels
DocumentationIssues describing a change to documentation.Issues describing a change to documentation.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.help wanted