Fix race in cache
This commit is contained in:
parent
e36960612a
commit
cfb846ee7e
11
registry/cache/cache.go
vendored
11
registry/cache/cache.go
vendored
@ -119,12 +119,10 @@ func (c *cache) get(service string) ([]*registry.Service, error) {
|
|||||||
// make a copy
|
// make a copy
|
||||||
cp := registry.Copy(services)
|
cp := registry.Copy(services)
|
||||||
|
|
||||||
// unlock the read lock
|
|
||||||
c.RUnlock()
|
|
||||||
|
|
||||||
// got services && within ttl so return cache
|
// got services && within ttl so return cache
|
||||||
if c.isValid(cp, ttl) {
|
if c.isValid(cp, ttl) {
|
||||||
// return servics
|
c.RUnlock()
|
||||||
|
// return services
|
||||||
return cp, nil
|
return cp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,8 +161,11 @@ func (c *cache) get(service string) ([]*registry.Service, error) {
|
|||||||
go c.run(service)
|
go c.run(service)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// unlock the read lock
|
||||||
|
c.RUnlock()
|
||||||
|
|
||||||
// get and return services
|
// get and return services
|
||||||
return get(service, services)
|
return get(service, cp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cache) set(service string, services []*registry.Service) {
|
func (c *cache) set(service string, services []*registry.Service) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user