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 if closing pool while a new connection is being created #105

Open
codestation opened this issue Mar 20, 2020 · 0 comments
Open

Comments

@codestation
Copy link

codestation commented Mar 20, 2020

Can reproduce consistently with this:

package email

import (
	"fmt"
	"net/smtp"
	"testing"
	"time"
)

func TestEmail_Deadlock(t *testing.T) {
	e := NewEmail()
	p, err := NewPool("smtp.gmail.com:587", 1, smtp.PlainAuth("", "[email protected]", "password123", "smtp.gmail.com"))
	if err != nil {
		t.Fatal(err)
	}
	err = p.Send(e, 3 * time.Second)
	if err == nil {
		t.Fatal("must have auth error")
	}
	fmt.Println(err)
	p.Close()
}

The main problem is that the created counter and the current clients array isn't in sync. On the makeOne() call the counter is incremented before the connection is ready, and only decremented when it has an error. An example would be:

  • Counter increased, created=1
  • Tries to create connection
  • Tries to send email and times out because it couldn't get a client.
  • Calls close() and created > 0 so enters loop and tries to read clients and locks.
  • The smtp connection times out and the counter is decreased, created=0
  • Stuck forever reading clients channel.
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

1 participant