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

Improve APNs http2 connection health check #568

Merged
merged 2 commits into from
May 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions gorush/notification_apns.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ func InitAPNSClient() error {
ApnsClient, err = newApnsClient(certificateKey)
}

if h2Transport, ok := ApnsClient.HTTPClient.Transport.(*http2.Transport); ok {
configureHTTP2ConnHealthCheck(h2Transport)
}

if err != nil {
LogError.Error("Transport Error:", err.Error())

Expand Down Expand Up @@ -155,11 +159,11 @@ func newApnsClient(certificate tls.Certificate) (*apns2.Client, error) {
IdleConnTimeout: idleConnTimeout,
}

transportErr := http2.ConfigureTransport(transport)
if transportErr != nil {
return nil, transportErr
if h2Transport, err := http2.ConfigureTransports(transport); err != nil {
return nil, err
} else {
configureHTTP2ConnHealthCheck(h2Transport)
}

client.HTTPClient.Transport = transport

return client, nil
Expand All @@ -184,16 +188,22 @@ func newApnsTokenClient(token *token.Token) (*apns2.Client, error) {
IdleConnTimeout: idleConnTimeout,
}

transportErr := http2.ConfigureTransport(transport)
if transportErr != nil {
return nil, transportErr
if h2Transport, err := http2.ConfigureTransports(transport); err != nil {
return nil, err
} else {
configureHTTP2ConnHealthCheck(h2Transport)
}

client.HTTPClient.Transport = transport

return client, nil
}

func configureHTTP2ConnHealthCheck(h2Transport *http2.Transport) {
h2Transport.ReadIdleTimeout = 1 * time.Second
h2Transport.PingTimeout = 1 * time.Second
}

func iosAlertDictionary(payload *payload.Payload, req PushNotification) *payload.Payload {
// Alert dictionary

Expand Down