Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deadlock with context #11

Open
delaneyj opened this issue Sep 20, 2021 · 1 comment · May be fixed by #13
Open

Deadlock with context #11

delaneyj opened this issue Sep 20, 2021 · 1 comment · May be fixed by #13

Comments

@delaneyj
Copy link

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?

said-saifi added a commit to alpacahq/errgroup that referenced this issue Mar 31, 2022
said-saifi added a commit to alpacahq/errgroup that referenced this issue Apr 1, 2022
said-saifi added a commit to alpacahq/errgroup that referenced this issue Apr 1, 2022
@said-saifi said-saifi linked a pull request Apr 1, 2022 that will close this issue
@said-saifi
Copy link

said-saifi commented Apr 1, 2022

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 added a commit to alpacahq/errgroup that referenced this issue Apr 1, 2022
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 a pull request may close this issue.

2 participants