Skip to content

Commit

Permalink
fix the concurrent map writes error
Browse files Browse the repository at this point in the history
  • Loading branch information
2403905 committed Dec 23, 2024
1 parent e032a6a commit 6307b41
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion registry/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ func (c *cache) isValid(services []*registry.Service, ttl time.Time) bool {
for _, n := range s.Nodes {
nttl := c.nttls[s.Name][n.Id]
if time.Since(nttl) > 0 {
delete(c.nttls, s.Name)
return false
}
}
Expand Down Expand Up @@ -222,6 +221,12 @@ func (c *cache) updateNodeTTLs(name string, nodes []*registry.Node) {
for _, node := range nodes {
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) {
Expand Down

0 comments on commit 6307b41

Please sign in to comment.