mirror of
https://github.com/go-micro/go-micro.git
synced 2025-01-17 17:44:30 +02:00
Fix registry cache broken (#2715)
* 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 <shuaihu.liu@shopee.com>
This commit is contained in:
parent
e9ceb66e32
commit
4d5b3b084f
5
registry/cache/cache.go
vendored
5
registry/cache/cache.go
vendored
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user