From cb1170205e21ff8c776d2ae1fb06a8322e2fe956 Mon Sep 17 00:00:00 2001 From: Gregorius Soedharmo Date: Thu, 5 Sep 2024 00:39:57 +0700 Subject: [PATCH] Fix SaveSnapshot timestamp metadata (#7334) --- src/core/Akka.Persistence/Snapshot/SnapshotStore.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/core/Akka.Persistence/Snapshot/SnapshotStore.cs b/src/core/Akka.Persistence/Snapshot/SnapshotStore.cs index d0ddcf56f7b..fe5d86540ac 100644 --- a/src/core/Akka.Persistence/Snapshot/SnapshotStore.cs +++ b/src/core/Akka.Persistence/Snapshot/SnapshotStore.cs @@ -75,7 +75,7 @@ private bool ReceiveSnapshotStore(object message) } else if (message is SaveSnapshot saveSnapshot) { - var metadata = new SnapshotMetadata(saveSnapshot.Metadata.PersistenceId, saveSnapshot.Metadata.SequenceNr, DateTime.UtcNow); + var metadata = new SnapshotMetadata(saveSnapshot.Metadata.PersistenceId, saveSnapshot.Metadata.SequenceNr, saveSnapshot.Metadata.Timestamp == DateTime.MinValue ? DateTime.UtcNow : saveSnapshot.Metadata.Timestamp); _breaker.WithCircuitBreaker(() => SaveAsync(metadata, saveSnapshot.Snapshot)) .ContinueWith(t => (!t.IsFaulted && !t.IsCanceled) @@ -83,7 +83,7 @@ private bool ReceiveSnapshotStore(object message) : new SaveSnapshotFailure(saveSnapshot.Metadata, t.IsFaulted ? TryUnwrapException(t.Exception) - : new OperationCanceledException("SaveAsync canceled, possibly due to timing out.")), + : new OperationCanceledException("SaveAsync canceled, possibly due to timing out.", TryUnwrapException(t.Exception))), _continuationOptions) .PipeTo(self, senderPersistentActor); } @@ -196,8 +196,7 @@ private bool ReceiveSnapshotStore(object message) private Exception TryUnwrapException(Exception e) { - var aggregateException = e as AggregateException; - if (aggregateException != null) + if (e is AggregateException aggregateException) { aggregateException = aggregateException.Flatten(); if (aggregateException.InnerExceptions.Count == 1)