Nothing Special   »   [go: up one dir, main page]

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

unclosetx: false positive detection with errgroup #32

Open
takatoshiono opened this issue Apr 15, 2020 · 2 comments
Open

unclosetx: false positive detection with errgroup #32

takatoshiono opened this issue Apr 15, 2020 · 2 comments

Comments

@takatoshiono
Copy link

When I use errgroup, zagane reports transaction must be closed. I think that it's false positive detection.

sample code:

func f5(ctx context.Context, client *spanner.Client) error {
	tx := client.ReadOnlyTransaction() // OK
	defer tx.Close()

	var eg errgroup.Group

	eg.Go(func() error {
		_ = tx // use tx
		return nil
	})

	if err := eg.Wait(); err != nil {
		return err
	}
	return nil
}
@tenntenn
Copy link
Member
tenntenn commented Jun 5, 2020

more simple sample code:

func f5(ctx context.Context, client *spanner.Client) error {
	tx := client.ReadOnlyTransaction() // OK
	defer tx.Close()

	func() error {
		_ = tx // use tx
		return nil
	}()

	return nil
}

@tenntenn
Copy link
Member
tenntenn commented Jun 5, 2020

I think this issue has two bugs.
First bug is false positive of tx := client.ReadOnlyTransaction().
Second bug is false positive of _ = tx // use tx.
Actually the below code zagane reports false positive in only case (2).

func() error {
	func(tx *spanner.ReadOnlyTransaction) {}(tx) // (1) OK
	_ = tx // (2) NG
	return nil
}()

This was referenced Sep 11, 2020
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

No branches or pull requests

2 participants