Skip to content

Commit

Permalink
Fix registry cache broken (#2715)
Browse files Browse the repository at this point in the history
* services is shared between routines, when application change services returned by get function may lead to other routine set a changed services to cache

* services is shared between routines, when application change services returned by get function may lead to other routine set a changed services to cache

---------

Co-authored-by: Shuaihu Liu <[email protected]>
  • Loading branch information
littlecoderonway and Shuaihu Liu authored Jul 2, 2024
1 parent e9ceb66 commit 4d5b3b0
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions registry/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,12 @@ func (c *cache) get(service string) ([]*registry.Service, error) {
}

// cache results
cp := util.Copy(services)
c.Lock()
c.set(service, util.Copy(services))
c.set(service, services)
c.Unlock()

return services, nil
return cp, nil
}

// watch service if not watched
Expand Down

0 comments on commit 4d5b3b0

Please sign in to comment.