1
0
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:
Roman Perekhod
2025-07-16 08:27:45 +02:00
committed by GitHub
parent f99a205b2b
commit ad73add529

View File

@ -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) {