diff --git a/gorush/notification_apns.go b/gorush/notification_apns.go index 66ed83e..ee7a5c3 100644 --- a/gorush/notification_apns.go +++ b/gorush/notification_apns.go @@ -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()) @@ -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 @@ -184,9 +188,10 @@ 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 @@ -194,6 +199,11 @@ func newApnsTokenClient(token *token.Token) (*apns2.Client, error) { 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