@@ -110,7 +110,7 @@ type Transport struct {
110
110
111
111
// PingTimeout is the timeout after which the connection will be closed
112
112
// if a response to Ping is not received.
113
- // Defaults to 1s .
113
+ // Defaults to 15s .
114
114
PingTimeout time.Duration
115
115
116
116
// ReadIdleTimeout is the timeout after which a health check using ping
@@ -144,17 +144,9 @@ func (t *Transport) disableCompression() bool {
144
144
return t .DisableCompression || (t .t1 != nil && t .t1 .DisableCompression )
145
145
}
146
146
147
- func (t * Transport ) readIdleTimeout () time.Duration {
148
- to := t .ReadIdleTimeout
149
- if to == 0 {
150
- to = 60 * time .Second
151
- }
152
- return to
153
- }
154
-
155
147
func (t * Transport ) pingTimeout () time.Duration {
156
148
if t .PingTimeout == 0 {
157
- return 1 * time .Second
149
+ return 15 * time .Second
158
150
}
159
151
return t .PingTimeout
160
152
@@ -708,8 +700,8 @@ func (cc *ClientConn) healthCheck() {
708
700
// We don't need to periodically ping in the health check, because the readLoop of ClientConn will
709
701
// trigger the healthCheck again if there is no frame received.
710
702
ctx , cancel := context .WithTimeout (context .Background (), pingTimeout )
703
+ defer cancel ()
711
704
err := cc .Ping (ctx )
712
- cancel ()
713
705
if err != nil {
714
706
cc .closeForLostPing ()
715
707
cc .t .connPool ().MarkDead (cc )
@@ -905,7 +897,7 @@ func (cc *ClientConn) Close() error {
905
897
906
898
// closes the client connection immediately. In-flight requests are interrupted.
907
899
func (cc * ClientConn ) closeForLostPing () error {
908
- err := errors .New ("http2: client connection force closed because ping frame was not answered " )
900
+ err := errors .New ("http2: client connection force closed because ping frame was not acknowledged " )
909
901
return cc .closeForError (err )
910
902
}
911
903
@@ -1761,15 +1753,16 @@ func (rl *clientConnReadLoop) run() error {
1761
1753
rl .closeWhenIdle = cc .t .disableKeepAlives () || cc .singleUse
1762
1754
gotReply := false // ever saw a HEADERS reply
1763
1755
gotSettings := false
1764
- to := cc .t .readIdleTimeout ()
1756
+ readIdleTimeout := cc .t .ReadIdleTimeout
1765
1757
var t * time.Timer
1766
- if to != 0 {
1767
- t = time .AfterFunc (to , cc .healthCheck )
1758
+ if readIdleTimeout != 0 {
1759
+ t = time .AfterFunc (readIdleTimeout , cc .healthCheck )
1760
+ defer t .Stop ()
1768
1761
}
1769
1762
for {
1770
1763
f , err := cc .fr .ReadFrame ()
1771
- if to != 0 {
1772
- t .Reset (to )
1764
+ if readIdleTimeout != 0 {
1765
+ t .Reset (readIdleTimeout )
1773
1766
}
1774
1767
if err != nil {
1775
1768
cc .vlogf ("http2: Transport readFrame error on conn %p: (%T) %v" , cc , err , err )
0 commit comments