Skip to content

Commit

Permalink
fix(Python): CMCs release lock for unhandled runtime exceptions (#979)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmcdonald3 authored Nov 12, 2024
1 parent 492dccb commit 1510b77
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ def __init__(self, wrapped):

def PutCacheEntry(self, input):
self.lock.Lock__()
val = self.wrapped.PutCacheEntry(input)
self.lock.Unlock()
try:
val = self.wrapped.PutCacheEntry(input)
finally:
self.lock.Unlock()
return val

def UpdateUsageMetadata(self, input):
self.lock.Lock__()
val = self.wrapped.UpdateUsageMetadata(input)
self.lock.Unlock()
try:
val = self.wrapped.UpdateUsageMetadata(input)
finally:
self.lock.Unlock()
return val

# NOT locked, as some sleeping might be involved
Expand All @@ -28,27 +32,35 @@ def GetCacheEntry(self, input):

def DeleteCacheEntry(self, input):
self.lock.Lock__()
val = self.wrapped.DeleteCacheEntry(input)
self.lock.Unlock()
try:
val = self.wrapped.DeleteCacheEntry(input)
finally:
self.lock.Unlock()
return val

def PutCacheEntry_k(self, input):
self.lock.Lock__()
val = self.wrapped.PutCacheEntry(input)
self.lock.Unlock()
try:
val = self.wrapped.PutCacheEntry(input)
finally:
self.lock.Unlock()
return val

def UpdateUsageMetadata_k(self, input):
self.lock.Lock__()
val = self.wrapped.UpdateUsageMetadata(input)
self.lock.Unlock()
try:
val = self.wrapped.UpdateUsageMetadata(input)
finally:
self.lock.Unlock()
return val

# This is the synchronization for GetCacheEntry and GetCacheEntry_k
def GetFromCacheInner(self, input):
self.lock.Lock__()
val = self.wrapped.GetFromCache(input)
self.lock.Unlock()
try:
val = self.wrapped.GetFromCache(input)
finally:
self.lock.Unlock()
return val

# NOT locked, because we sleep. Calls GetFromCache which IS synchronized.
Expand All @@ -73,8 +85,10 @@ def GetCacheEntry_k(self, input):

def DeleteCacheEntry_k(self, input):
self.lock.Lock__()
val = self.wrapped.DeleteCacheEntry(input)
self.lock.Unlock()
try:
val = self.wrapped.DeleteCacheEntry(input)
finally:
self.lock.Unlock()
return val

def __str__(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,56 +12,74 @@ def __init__(self, wrapped):

def PutCacheEntry(self, input):
self.lock.Lock__()
val = self.wrapped.PutCacheEntry(input)
self.lock.Unlock()
try:
val = self.wrapped.PutCacheEntry(input)
finally:
self.lock.Unlock()
return val

def UpdateUsageMetadata(self, input):
self.lock.Lock__()
val = self.wrapped.UpdateUsageMetadata(input)
self.lock.Unlock()
try:
val = self.wrapped.UpdateUsageMetadata(input)
finally:
self.lock.Unlock()
return val

def GetCacheEntry(self, input):
self.lock.Lock__()
val = self.wrapped.GetCacheEntry(input)
self.lock.Unlock()
try:
val = self.wrapped.GetCacheEntry(input)
finally:
self.lock.Unlock()
return val

def DeleteCacheEntry(self, input):
self.lock.Lock__()
val = self.wrapped.DeleteCacheEntry(input)
self.lock.Unlock()
try:
val = self.wrapped.DeleteCacheEntry(input)
finally:
self.lock.Unlock()
return val

def PutCacheEntry_k(self, input):
self.lock.Lock__()
val = self.wrapped.PutCacheEntry(input)
self.lock.Unlock()
try:
val = self.wrapped.PutCacheEntry(input)
finally:
self.lock.Unlock()
return val

def UpdateUsageMetadata_k(self, input):
self.lock.Lock__()
val = self.wrapped.UpdateUsageMetadata(input)
self.lock.Unlock()
try:
val = self.wrapped.UpdateUsageMetadata(input)
finally:
self.lock.Unlock()
return val

def GetFromCacheInner(self, input):
self.lock.Lock__()
val = self.wrapped.GetFromCache(input)
self.lock.Unlock()
try:
val = self.wrapped.GetFromCache(input)
finally:
self.lock.Unlock()
return val

def GetCacheEntry_k(self, input):
self.lock.Lock__()
val = self.wrapped.GetCacheEntry(input)
self.lock.Unlock()
try:
val = self.wrapped.GetCacheEntry(input)
finally:
self.lock.Unlock()
return val

def DeleteCacheEntry_k(self, input):
self.lock.Lock__()
val = self.wrapped.DeleteCacheEntry(input)
self.lock.Unlock()
try:
val = self.wrapped.DeleteCacheEntry(input)
finally:
self.lock.Unlock()
return val

def __str__(self):
Expand Down

0 comments on commit 1510b77

Please sign in to comment.