Skip to content

http2: potential connection/goroutine leaked #238

@dandehoon

Description

@dandehoon

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions