Skip to content

Commit e733ed9

Browse files
Update pool.go (#55)
* Update pool.go 修复new多个client时底层共用一个pool导致所有client的ip相同问题 * Update golangci-lint.yml 升级golint到1.48.0 * Update pool.go 删除无用代码
1 parent dacdd0c commit e733ed9

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ jobs:
1515
- name: golangci-lint
1616
uses: golangci/golangci-lint-action@v2
1717
with:
18-
version: v1.45.2
19-
args: --skip-dirs=examples --skip-files=.*_test.go$
18+
version: v1.48.0
19+
args: --skip-dirs=examples --skip-files=.*_test.go$

pool.go

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ import (
99
"time"
1010
)
1111

12-
var onceInit sync.Once
13-
var onceMonitor sync.Once
14-
var instance *AddressPool
15-
1612
const (
1713
available string = "available"
1814
unavailable string = "unavailable"
@@ -21,22 +17,19 @@ const (
2117

2218
// AddressPool registry address pool
2319
type AddressPool struct {
24-
protocol string
25-
addressMap map[string]string
26-
status map[string]string
27-
mutex sync.RWMutex
20+
protocol string
21+
addressMap map[string]string
22+
status map[string]string
23+
mutex sync.RWMutex
24+
onceMonitor sync.Once
2825
}
2926

3027
// NewPool Get registry pool instance
3128
func NewPool(protocol string) *AddressPool {
32-
onceInit.Do(func() {
33-
instance = &AddressPool{
34-
protocol: protocol,
35-
addressMap: make(map[string]string),
36-
status: make(map[string]string),
37-
}
38-
})
39-
return instance
29+
return &AddressPool{
30+
addressMap: make(map[string]string),
31+
status: make(map[string]string),
32+
}
4033
}
4134

4235
// SetAddress set addresses to pool
@@ -89,7 +82,7 @@ func (p *AddressPool) checkConnectivity() {
8982

9083
//Monitor monitor each service center network connectivity
9184
func (p *AddressPool) Monitor() {
92-
onceMonitor.Do(func() {
85+
p.onceMonitor.Do(func() {
9386
p.checkConnectivity()
9487
var interval time.Duration
9588
v, isExist := os.LookupEnv(EnvCheckSCIInterval)

0 commit comments

Comments
 (0)