From 54777a61ca6a0efc127efd0c28d5f5489fdeb9fd Mon Sep 17 00:00:00 2001 From: closer Date: Wed, 21 Feb 2018 15:43:26 +0900 Subject: [PATCH] Add TCP idle timeout (https://github.com/sideshow/apns2/issues/24) --- client.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 221a7df6..eabc3bea 100644 --- a/client.go +++ b/client.go @@ -37,6 +37,11 @@ var ( // TCPKeepAlive specifies the keep-alive period for an active network // connection. If zero, keep-alives are not enabled. TCPKeepAlive = 60 * time.Second + // TCPIdleTimeout specifies the maximum amount of time an idle + // (keep-alive) connection will remain idle before closing + // itself. + // If zero, are no limit. + TCPIdleTimeout = 0 * time.Second ) // DialTLS is the default dial function for creating TLS connections for @@ -80,6 +85,9 @@ func NewClient(certificate tls.Certificate) *Client { tlsConfig.BuildNameToCertificate() } transport := &http2.Transport{ + http2.t1: &http.Transport{ + IdleConnTimeout: TCPIdleTimeout, + }, TLSClientConfig: tlsConfig, DialTLS: DialTLS, } @@ -103,7 +111,10 @@ func NewClient(certificate tls.Certificate) *Client { // connection and disconnection as a denial-of-service attack. func NewTokenClient(token *token.Token) *Client { transport := &http2.Transport{ - DialTLS: DialTLS, + http2.t1: &http.Transport{ + IdleConnTimeout: TCPIdleTimeout, + }, + DialTLS: DialTLS, } return &Client{ Token: token,