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

Data Race in Connection Pool #141

Open
dougnd opened this issue Feb 19, 2021 · 0 comments · May be fixed by #142
Open

Data Race in Connection Pool #141

dougnd opened this issue Feb 19, 2021 · 0 comments · May be fixed by #142

Comments

@dougnd
Copy link

dougnd commented Feb 19, 2021

We've recently been running using the connection pool and discovered a data race. Running the following snippet:

func main() {
	auth := <auth code here>
	pool, err := email.NewPool(
		"<address here>", 4, auth)
	if err != nil {
		panic(fmt.Errorf("failed to create email pool: %v", err))
	}

	var wg sync.WaitGroup
	n := 10
	wg.Add(n)

	for i := 0; i < n; i++ {
		go func() {
			var err error
			err = pool.Send(&email.Email{
				To:   []string{"foo@example.com"},
				From: "foo@example.com",
				Text: []byte("This is a test"),
			}, time.Second*10)
			if err != nil {
				panic(err)
			}
			wg.Done()
		}()
	}
	wg.Wait()
}

With the Go race detector enabled:

go run -race main.go

Yields error messages like:

==================
WARNING: DATA RACE
Read at 0x00c0000d6028 by goroutine 12:
  github.com/jordan-wright/email.(*Pool).get()
      /Users/dndawso/go/pkg/mod/github.com/jordan-wright/email@v4.0.1-0.20210109023952-943e75fe5223+incompatible/pool.go:87 +0xac
  github.com/jordan-wright/email.(*Pool).Send()
      /Users/dndawso/go/pkg/mod/github.com/jordan-wright/email@v4.0.1-0.20210109023952-943e75fe5223+incompatible/pool.go:283 +0x95
  main.main.func1()
      /Users/dndawso/repos/emailtest/main.go:80 +0x244

Previous write at 0x00c0000d6028 by goroutine 10:
  github.com/jordan-wright/email.(*Pool).inc()
      /Users/dndawso/go/pkg/mod/github.com/jordan-wright/email@v4.0.1-0.20210109023952-943e75fe5223+incompatible/pool.go:155 +0x191
  github.com/jordan-wright/email.(*Pool).makeOne.func1()
      /Users/dndawso/go/pkg/mod/github.com/jordan-wright/email@v4.0.1-0.20210109023952-943e75fe5223+incompatible/pool.go:172 +0x3c

Goroutine 12 (running) created at:
  main.main()
      /Users/dndawso/repos/emailtest/main.go:77 +0x205

Goroutine 10 (running) created at:
  github.com/jordan-wright/email.(*Pool).makeOne()
      /Users/dndawso/go/pkg/mod/github.com/jordan-wright/email@v4.0.1-0.20210109023952-943e75fe5223+incompatible/pool.go:171 +0x4c
  github.com/jordan-wright/email.(*Pool).get()
      /Users/dndawso/go/pkg/mod/github.com/jordan-wright/email@v4.0.1-0.20210109023952-943e75fe5223+incompatible/pool.go:88 +0x34d
  github.com/jordan-wright/email.(*Pool).Send()
      /Users/dndawso/go/pkg/mod/github.com/jordan-wright/email@v4.0.1-0.20210109023952-943e75fe5223+incompatible/pool.go:283 +0x95
  main.main.func1()
      /Users/dndawso/repos/emailtest/main.go:80 +0x244
==================

I believe I see the culprit (references to p.created without locking p.mut) and will work on a pull request.

dougnd added a commit to dougnd/email that referenced this issue Feb 19, 2021
@dougnd dougnd linked a pull request Feb 19, 2021 that will close this issue
eos175 added a commit to eos175/email that referenced this issue Dec 17, 2021
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.

1 participant