aboutsummaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authorGravatar Zhengkai Wang <xuxiao415@foxmail.com> 2023-05-12 15:49:37 +0800
committerGravatar GitHub <noreply@github.com> 2023-05-12 09:49:37 +0200
commitd2f97fc426ed451e64dc8e35e7f87a1d4a2d7bde (patch)
treeb811741e4f815cb0492938db43adfe0b4e5652ff /client.go
parentadd concurrency for client's HostClient map (#1550) (diff)
downloadfasthttp-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.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/client.go b/client.go
index 8800571..d37ed33 100644
--- a/client.go
+++ b/client.go
@@ -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)
}