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

http2: potential connection/goroutine leaked #238

Open
danztran opened this issue Nov 11, 2024 · 0 comments
Open

http2: potential connection/goroutine leaked #238

danztran opened this issue Nov 11, 2024 · 0 comments

Comments

@danztran
Copy link

danztran commented Nov 11, 2024

Hi! I noticed that creating a new client with default options might lead to an http2 connection leak. I found a handy solution using the ⁠IdleConnTimeout option from this helpful Pull Request: golang.org/x/net#170. I was thinking it would be really cool if the library could automatically close these connections by default, or at least give developers a heads-up to use ⁠CloseIdleConnections in their code. This would save everyone a bit of trouble and debugging time! What do you think?

Before After some time
image image

Got this all sorted out on 11/07 with

client := apns2.NewTokenClient(t)
client.HTTPClient.Transport = &http2.Transport{
	DialTLS:         apns2.DialTLS,
	ReadIdleTimeout: apns2.ReadIdleTimeout,
	IdleConnTimeout: 90 * time.Second, // handle conn leak
}
image
  1. What version of Go are you using? go version
    1.23.2
  2. What OS and processor architecture are you using? go env
    Linux - amd64
  3. What did you do?
    I used the method ⁠apns2.NewTokenClient() to create new client and use PushWithContext() send a push notification.
  4. What did you expect to see?
    The amount of goroutines should reduce over time and return to normal.
  5. What did you see instead?
    Goroutines keep increasing under high load due to http2 keeping open new connections without automatically closing them.
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