fix: concurrent map access
This commit is contained in:
parent
a9e7fee369
commit
164601cfd2
@ -242,11 +242,12 @@ func (f *FastestFilter) Filter(nodes []Node) []Node {
|
||||
now := time.Now().Unix()
|
||||
|
||||
var getNodeLatency = func(node Node) int {
|
||||
if f.pingResultTTL[node.ID] < now {
|
||||
f.mu.Lock()
|
||||
f.pingResultTTL[node.ID] = now + 5 // tmp
|
||||
defer f.mu.Unlock()
|
||||
|
||||
if f.pingResultTTL[node.ID] < now {
|
||||
f.pingResultTTL[node.ID] = now + 5 // tmp
|
||||
|
||||
// get latency
|
||||
go func(node Node) {
|
||||
latency := f.doTcpPing(node.Addr)
|
||||
@ -254,9 +255,10 @@ func (f *FastestFilter) Filter(nodes []Node) []Node {
|
||||
ttl := 300 - int64(120*r.Float64())
|
||||
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
|
||||
f.pingResult[node.ID] = latency
|
||||
f.pingResultTTL[node.ID] = now + ttl
|
||||
defer f.mu.Unlock()
|
||||
}(node)
|
||||
}
|
||||
return f.pingResult[node.ID]
|
||||
|
Loading…
Reference in New Issue
Block a user