diff --git a/src/DurableTask.Netherite/PartitionState/ReassemblyState.cs b/src/DurableTask.Netherite/PartitionState/ReassemblyState.cs index 8774a72..9e72cf9 100644 --- a/src/DurableTask.Netherite/PartitionState/ReassemblyState.cs +++ b/src/DurableTask.Netherite/PartitionState/ReassemblyState.cs @@ -64,7 +64,13 @@ namespace DurableTask.Netherite if (evt.IsLast) { - evt.ReassembledEvent = FragmentationAndReassembly.Reassemble(this.Fragments[group], evt, effects.Partition); + if (!this.Fragments.TryGetValue(group, out var list)) + { + effects.EventTraceHelper.TraceEventProcessingDetail($"Discarded fragment ${evt.Fragment} for expired group {group}"); + return; + } + + evt.ReassembledEvent = FragmentationAndReassembly.Reassemble(list, evt, effects.Partition); effects.EventDetailTracer?.TraceEventProcessingDetail($"Reassembled {evt.ReassembledEvent}"); @@ -100,9 +106,13 @@ namespace DurableTask.Netherite { this.Fragments[group] = list = new List(); } - else + else { - list = this.Fragments[group]; + if (!this.Fragments.TryGetValue(group, out list)) + { + effects.EventTraceHelper.TraceEventProcessingDetail($"Discarded fragment ${evt.Fragment} for expired group {group}"); + return; + } } list.Add(evt);