From 6c255117b5ef312b55cc83bd5389f37e01e0ccde Mon Sep 17 00:00:00 2001 From: sebastianburckhardt Date: Wed, 19 Apr 2023 16:40:50 -0700 Subject: [PATCH 1/2] fixes a data race in memory tracker that can cause divide-by-zero exceptions --- src/DurableTask.Netherite/StorageLayer/Faster/MemoryTracker.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/DurableTask.Netherite/StorageLayer/Faster/MemoryTracker.cs b/src/DurableTask.Netherite/StorageLayer/Faster/MemoryTracker.cs index b685f0f6..2a7fa39a 100644 --- a/src/DurableTask.Netherite/StorageLayer/Faster/MemoryTracker.cs +++ b/src/DurableTask.Netherite/StorageLayer/Faster/MemoryTracker.cs @@ -41,7 +41,8 @@ public CacheTracker NewCacheTracker(FasterKV store, int partitionId, CacheDebugg public void UpdateTargetSizes() { - if (this.stores.Count > 0) + int numberOfStores = this.stores.Count; + if (numberOfStores > 0) { long targetSize = this.maxCacheSize / this.stores.Count; foreach (var s in this.stores.Keys) From 0172a0bfc634e73c37158efe86f4641a99a7e283 Mon Sep 17 00:00:00 2001 From: Sebastian Burckhardt Date: Fri, 21 Apr 2023 09:23:34 -0700 Subject: [PATCH 2/2] Add comment to clarify that there is a potential race condition Co-authored-by: David Justo --- src/DurableTask.Netherite/StorageLayer/Faster/MemoryTracker.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DurableTask.Netherite/StorageLayer/Faster/MemoryTracker.cs b/src/DurableTask.Netherite/StorageLayer/Faster/MemoryTracker.cs index 2a7fa39a..3291f695 100644 --- a/src/DurableTask.Netherite/StorageLayer/Faster/MemoryTracker.cs +++ b/src/DurableTask.Netherite/StorageLayer/Faster/MemoryTracker.cs @@ -41,6 +41,7 @@ public CacheTracker NewCacheTracker(FasterKV store, int partitionId, CacheDebugg public void UpdateTargetSizes() { + // store count to avoid race condition where count goes to zero and causes divide-by-zero error int numberOfStores = this.stores.Count; if (numberOfStores > 0) {