Skip to content

http2: export CloseIdleConnections in client connection pool #71

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
12 changes: 6 additions & 6 deletions http2/client_conn_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ type ClientConnPool interface {
MarkDead(*ClientConn)
}

// clientConnPoolIdleCloser is the interface implemented by ClientConnPool
// ClientConnPoolIdleCloser is the interface implemented by ClientConnPool
// implementations which can close their idle connections.
type clientConnPoolIdleCloser interface {
type ClientConnPoolIdleCloser interface {
ClientConnPool
closeIdleConnections()
CloseIdleConnections()
}

var (
_ clientConnPoolIdleCloser = (*clientConnPool)(nil)
_ clientConnPoolIdleCloser = noDialClientConnPool{}
_ ClientConnPoolIdleCloser = (*clientConnPool)(nil)
_ ClientConnPoolIdleCloser = noDialClientConnPool{}
)

// TODO: use singleflight for dialing and addConnCalls?
Expand Down Expand Up @@ -237,7 +237,7 @@ func (p *clientConnPool) MarkDead(cc *ClientConn) {
delete(p.keys, cc)
}

func (p *clientConnPool) closeIdleConnections() {
func (p *clientConnPool) CloseIdleConnections() {
p.mu.Lock()
defer p.mu.Unlock()
// TODO: don't close a cc if it was just added to the pool
Expand Down
4 changes: 2 additions & 2 deletions http2/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,8 @@ func (t *Transport) RoundTripOpt(req *http.Request, opt RoundTripOpt) (*http.Res
// connected from previous requests but are now sitting idle.
// It does not interrupt any connections currently in use.
func (t *Transport) CloseIdleConnections() {
if cp, ok := t.connPool().(clientConnPoolIdleCloser); ok {
cp.closeIdleConnections()
if cp, ok := t.connPool().(ClientConnPoolIdleCloser); ok {
cp.CloseIdleConnections()
}
}

Expand Down