fix the problem: HostClient maybe delete when pendingClientRequests > 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>
This commit is contained in:
Zhengkai Wang
2023-05-12 15:49:37 +08:00
committed by GitHub
parent 7ea3b6330e
commit d2f97fc426
+6 -3
View File
@@ -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()
@@ -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)
}