mirror of
https://github.com/go-micro/go-micro.git
synced 2025-08-04 21:42:57 +02:00
fix the concurrent map writes error (#2794)
This commit is contained in:
7
registry/cache/cache.go
vendored
7
registry/cache/cache.go
vendored
@ -100,7 +100,6 @@ func (c *cache) isValid(services []*registry.Service, ttl time.Time) bool {
|
|||||||
for _, n := range s.Nodes {
|
for _, n := range s.Nodes {
|
||||||
nttl := c.nttls[s.Name][n.Id]
|
nttl := c.nttls[s.Name][n.Id]
|
||||||
if time.Since(nttl) > 0 {
|
if time.Since(nttl) > 0 {
|
||||||
delete(c.nttls, s.Name)
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -222,6 +221,12 @@ func (c *cache) updateNodeTTLs(name string, nodes []*registry.Node) {
|
|||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
c.nttls[name][node.Id] = time.Now().Add(c.opts.TTL)
|
c.nttls[name][node.Id] = time.Now().Add(c.opts.TTL)
|
||||||
}
|
}
|
||||||
|
// clean up expired nodes
|
||||||
|
for nodeId, nttl := range c.nttls[name] {
|
||||||
|
if time.Since(nttl) > 0 {
|
||||||
|
delete(c.nttls[name], nodeId)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cache) update(res *registry.Result) {
|
func (c *cache) update(res *registry.Result) {
|
||||||
|
Reference in New Issue
Block a user