TBR: services/allocator/allocatord: Fix deadlock
There was a missing Unlock() in checkOwner(). Refactor to make it easier
to read and debug.
Change-Id: I3c9a6ae5a8b6e492fb729ed8758323c03257eb72
diff --git a/services/allocator/allocatord/cache.go b/services/allocator/allocatord/cache.go
index 042024c..87cb3dd 100644
--- a/services/allocator/allocatord/cache.go
+++ b/services/allocator/allocatord/cache.go
@@ -38,9 +38,10 @@
instanceCacheMutex.Lock()
if instanceCache == nil {
instanceCache = lru.New(maxInstancesFlag)
- instanceCacheMutex.Unlock()
- } else if v, ok := instanceCache.Get(email); ok {
- instanceCacheMutex.Unlock()
+ }
+ v, ok := instanceCache.Get(email)
+ instanceCacheMutex.Unlock()
+ if ok {
if instances, ok := v.([]allocator.Instance); !ok {
// Our cache code is broken. Proceed to refresh entry.
ctx.Errorf("invalid cache entry type %T for email %v", v, email)