errgroup icon indicating copy to clipboard operation
errgroup copied to clipboard

Deadlock with context

Open delaneyj opened this issue 4 years ago • 1 comments

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?

delaneyj avatar Sep 20 '21 17:09 delaneyj

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

said-saifi avatar Apr 01 '22 07:04 said-saifi