errgroup
errgroup copied to clipboard
Deadlock with context
package main
import (
"fmt"
"context"
"github.com/neilotoole/errgroup"
)
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
eg, ctx := errgroup.WithContextN(ctx, 1, 1)
eg.Go(func() error { return nil })
eg.Go(func() error { return nil })
eg.Go(func() error { return nil })
eg.Go(func() error { return fmt.Errorf("sample error") })
eg.Go(func() error { return nil })
eg.Go(func() error { return nil })
eg.Go(func() error { return nil })
if err := eg.Wait(); err != nil {
fmt.Printf("Error group error: %s", err.Error())
}
}
If you run this multiple times there is a chance at deadlocking. What am I doing wrong here?
This is fixed in #13. To try it before #13 gets merged:
go mod edit -replace github.com/neilotoole/errgroup=github.com/said-saifi/errgroup@master