Skip to content

Commit eee2987

Browse files
author
Jia Zhan
committed
http2: export CloseIfIdle in ClientConn
1 parent a91f071 commit eee2987

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

http2/client_conn_pool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func (p *clientConnPool) closeIdleConnections() {
248248
// break some caller's RoundTrip.
249249
for _, vv := range p.conns {
250250
for _, cc := range vv {
251-
cc.closeIfIdle()
251+
cc.CloseIfIdle()
252252
}
253253
}
254254
}

http2/transport.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -761,14 +761,16 @@ func (cc *ClientConn) tooIdleLocked() bool {
761761
// onIdleTimeout is called from a time.AfterFunc goroutine. It will
762762
// only be called when we're idle, but because we're coming from a new
763763
// goroutine, there could be a new request coming in at the same time,
764-
// so this simply calls the synchronized closeIfIdle to shut down this
765-
// connection. The timer could just call closeIfIdle, but this is more
764+
// so this simply calls the synchronized CloseIfIdle to shut down this
765+
// connection. The timer could just call CloseIfIdle, but this is more
766766
// clear.
767767
func (cc *ClientConn) onIdleTimeout() {
768-
cc.closeIfIdle()
768+
cc.CloseIfIdle()
769769
}
770770

771-
func (cc *ClientConn) closeIfIdle() {
771+
// CloseIfIdle closes the client connection if it's idle.
772+
// exported for user-specified ClientConnPool usage.
773+
func (cc *ClientConn) CloseIfIdle() {
772774
cc.mu.Lock()
773775
if len(cc.streams) > 0 {
774776
cc.mu.Unlock()
@@ -1799,7 +1801,7 @@ func (rl *clientConnReadLoop) run() error {
17991801
return err
18001802
}
18011803
if rl.closeWhenIdle && gotReply && maybeIdle {
1802-
cc.closeIfIdle()
1804+
cc.CloseIfIdle()
18031805
}
18041806
}
18051807
}

0 commit comments

Comments
 (0)