Skip to content

Commit

Permalink
fix the problem: HostClient maybe delete when pendingClientRequests >…
Browse files Browse the repository at this point in the history
… 0 (#1562)

* add the functions to get host clients

* add concurrency for client's HostClient map

* delete test code

* add lock in once block

* fix the problem: HostClient maybe delete when pendingClientRequests > 0

* fix the problem: HostClient maybe delete when pendingClientRequests > 0

---------

Co-authored-by: wangzhengkai.wzk <wangzhengkai.wzk@alibaba-inc.com>
  • Loading branch information
xuxiao415 and wangzhengkai.wzk committed May 12, 2023
1 parent 7ea3b63 commit d2f97fc
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,10 @@ func (c *Client) Do(req *Request, resp *Response) error {
m = c.ms
}
hc := m[string(host)]
if hc != nil {
atomic.AddInt32(&hc.pendingClientRequests, 1)
defer atomic.AddInt32(&hc.pendingClientRequests, -1)
}
c.mLock.RUnlock()
if hc == nil {
c.mLock.Lock()
Expand Down Expand Up @@ -545,12 +549,11 @@ func (c *Client) Do(req *Request, resp *Response) error {
startCleaner = true
}
}
atomic.AddInt32(&hc.pendingClientRequests, 1)
defer atomic.AddInt32(&hc.pendingClientRequests, -1)
c.mLock.Unlock()
}

atomic.AddInt32(&hc.pendingClientRequests, 1)
defer atomic.AddInt32(&hc.pendingClientRequests, -1)

if startCleaner {
go c.mCleaner(m)
}
Expand Down

0 comments on commit d2f97fc

Please sign in to comment.