Skip to content

http2: export CloseIfIdle in ClientConn #72

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion http2/client_conn_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (p *clientConnPool) closeIdleConnections() {
// break some caller's RoundTrip.
for _, vv := range p.conns {
for _, cc := range vv {
cc.closeIfIdle()
cc.CloseIfIdle()
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions http2/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,14 +761,16 @@ func (cc *ClientConn) tooIdleLocked() bool {
// onIdleTimeout is called from a time.AfterFunc goroutine. It will
// only be called when we're idle, but because we're coming from a new
// goroutine, there could be a new request coming in at the same time,
// so this simply calls the synchronized closeIfIdle to shut down this
// connection. The timer could just call closeIfIdle, but this is more
// so this simply calls the synchronized CloseIfIdle to shut down this
// connection. The timer could just call CloseIfIdle, but this is more
// clear.
func (cc *ClientConn) onIdleTimeout() {
cc.closeIfIdle()
cc.CloseIfIdle()
}

func (cc *ClientConn) closeIfIdle() {
// CloseIfIdle closes the client connection if it's idle.
// exported for user-specified ClientConnPool usage.
func (cc *ClientConn) CloseIfIdle() {
cc.mu.Lock()
if len(cc.streams) > 0 {
cc.mu.Unlock()
Expand Down Expand Up @@ -1799,7 +1801,7 @@ func (rl *clientConnReadLoop) run() error {
return err
}
if rl.closeWhenIdle && gotReply && maybeIdle {
cc.closeIfIdle()
cc.CloseIfIdle()
}
}
}
Expand Down