diff --git a/AwsCryptographicMaterialProviders/runtimes/python/src/aws_cryptographic_material_providers/internaldafny/extern/StormTrackingCMC.py b/AwsCryptographicMaterialProviders/runtimes/python/src/aws_cryptographic_material_providers/internaldafny/extern/StormTrackingCMC.py index 5164cebde..032187eb5 100644 --- a/AwsCryptographicMaterialProviders/runtimes/python/src/aws_cryptographic_material_providers/internaldafny/extern/StormTrackingCMC.py +++ b/AwsCryptographicMaterialProviders/runtimes/python/src/aws_cryptographic_material_providers/internaldafny/extern/StormTrackingCMC.py @@ -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 @@ -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. @@ -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): diff --git a/AwsCryptographicMaterialProviders/runtimes/python/src/aws_cryptographic_material_providers/internaldafny/extern/SynchronizedLocalCMC.py b/AwsCryptographicMaterialProviders/runtimes/python/src/aws_cryptographic_material_providers/internaldafny/extern/SynchronizedLocalCMC.py index 122b54c84..2f08cd81c 100644 --- a/AwsCryptographicMaterialProviders/runtimes/python/src/aws_cryptographic_material_providers/internaldafny/extern/SynchronizedLocalCMC.py +++ b/AwsCryptographicMaterialProviders/runtimes/python/src/aws_cryptographic_material_providers/internaldafny/extern/SynchronizedLocalCMC.py @@ -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):