Skip to content

Commit

Permalink
Only remove a HostClient from Client if it is unused
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdubbelboer committed Nov 1, 2018
1 parent 1925153 commit aebec40
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions client.go
Expand Up @@ -423,11 +423,15 @@ func (c *Client) Do(req *Request, resp *Response) error {

func (c *Client) mCleaner(m map[string]*HostClient) {
mustStop := false

for {
t := time.Now()
c.mLock.Lock()
for k, v := range m {
if t.Sub(v.LastUseTime()) > time.Minute {
v.connsLock.Lock()
shouldRemove := v.connsCount == 0
v.connsLock.Unlock()

if shouldRemove {
delete(m, k)
}
}
Expand Down

0 comments on commit aebec40

Please sign in to comment.