diff options
author | Zhengkai Wang <xuxiao415@foxmail.com> | 2023-05-12 15:49:37 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-12 09:49:37 +0200 |
commit | d2f97fc426ed451e64dc8e35e7f87a1d4a2d7bde (patch) | |
tree | b811741e4f815cb0492938db43adfe0b4e5652ff /client.go | |
parent | add concurrency for client's HostClient map (#1550) (diff) | |
download | fasthttp-d2f97fc426ed451e64dc8e35e7f87a1d4a2d7bde.tar.gz fasthttp-d2f97fc426ed451e64dc8e35e7f87a1d4a2d7bde.tar.bz2 fasthttp-d2f97fc426ed451e64dc8e35e7f87a1d4a2d7bde.zip |
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>
Diffstat (limited to 'client.go')
-rw-r--r-- | client.go | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -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) } |