fix major deadlock in registry cache
This commit is contained in:
parent
05eacd74c8
commit
c4b6d0f3a8
17
registry/cache/cache.go
vendored
17
registry/cache/cache.go
vendored
@ -100,7 +100,7 @@ func (c *cache) quit() bool {
|
|||||||
|
|
||||||
func (c *cache) del(service string) {
|
func (c *cache) del(service string) {
|
||||||
// don't blow away cache in error state
|
// don't blow away cache in error state
|
||||||
if err := c.getStatus(); err != nil {
|
if err := c.status; err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// otherwise delete entries
|
// otherwise delete entries
|
||||||
@ -116,13 +116,14 @@ func (c *cache) get(service string) ([]*registry.Service, error) {
|
|||||||
services := c.cache[service]
|
services := c.cache[service]
|
||||||
// get cache ttl
|
// get cache ttl
|
||||||
ttl := c.ttls[service]
|
ttl := c.ttls[service]
|
||||||
|
|
||||||
// got services && within ttl so return cache
|
|
||||||
if c.isValid(services, ttl) {
|
|
||||||
// make a copy
|
// make a copy
|
||||||
cp := registry.Copy(services)
|
cp := registry.Copy(services)
|
||||||
// unlock the read
|
|
||||||
|
// unlock the read lock
|
||||||
c.RUnlock()
|
c.RUnlock()
|
||||||
|
|
||||||
|
// got services && within ttl so return cache
|
||||||
|
if c.isValid(cp, ttl) {
|
||||||
// return servics
|
// return servics
|
||||||
return cp, nil
|
return cp, nil
|
||||||
}
|
}
|
||||||
@ -136,8 +137,9 @@ func (c *cache) get(service string) ([]*registry.Service, error) {
|
|||||||
if len(cached) > 0 {
|
if len(cached) > 0 {
|
||||||
// set the error status
|
// set the error status
|
||||||
c.setStatus(err)
|
c.setStatus(err)
|
||||||
|
|
||||||
// return the stale cache
|
// return the stale cache
|
||||||
return registry.Copy(cached), nil
|
return cached, nil
|
||||||
}
|
}
|
||||||
// otherwise return error
|
// otherwise return error
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -161,9 +163,6 @@ 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, services)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user