From 785cda387f4501f384824cba64bca753458d2298 Mon Sep 17 00:00:00 2001 From: Menno van Lavieren Date: Thu, 2 May 2019 13:26:59 +0200 Subject: [PATCH] Enforce loading of the flowstore before lookingup continuations, to prevent a common misuse that leads to data loss. --- Tapeti.Flow/Default/FlowStore.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Tapeti.Flow/Default/FlowStore.cs b/Tapeti.Flow/Default/FlowStore.cs index 2597007..8fb9dc2 100644 --- a/Tapeti.Flow/Default/FlowStore.cs +++ b/Tapeti.Flow/Default/FlowStore.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using Tapeti.Flow.FlowHelpers; @@ -16,6 +17,7 @@ namespace Tapeti.Flow.Default private readonly IFlowRepository repository; private volatile bool inUse; + private volatile bool loaded; public FlowStore(IFlowRepository repository) { @@ -40,17 +42,25 @@ namespace Tapeti.Flow.Default foreach (var continuation in flowStateRecord.Value.Continuations) continuationLookup.GetOrAdd(continuation.Key, flowStateRecord.Key); } + + loaded = true; } public Task FindFlowID(Guid continuationID) { + if (!loaded) + throw new InvalidOperationException("Flow store is not yet loaded."); + return Task.FromResult(continuationLookup.TryGetValue(continuationID, out var result) ? result : (Guid?)null); } public async Task LockFlowState(Guid flowID) { + if (!loaded && Debugger.IsAttached) + throw new InvalidOperationException("Flow store should be loaded before storing flows."); + inUse = true; var flowStatelock = new FlowStateLock(this, flowID, await locks.GetLock(flowID));