mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-16 16:17:38 +03:00
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:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user