From 2502ea96d726a443306226e2e81d3ab4d5a08e59 Mon Sep 17 00:00:00 2001 From: Aaron Stannard Date: Fri, 23 Aug 2024 12:22:30 -0500 Subject: [PATCH] Akka.Persistence.Sql.Common: harden `SqlJournal` and `SqlSnapshotStore` against initialization failures (#7325) * Harden SQL journal in the event of failed initialization * harden snapshot store too --------- Co-authored-by: Gregorius Soedharmo --- .../Akka.Persistence.Sql.Common/Journal/SqlJournal.cs | 5 +++-- .../Akka.Persistence.Sql.Common/Snapshot/SqlSnapshotStore.cs | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/contrib/persistence/Akka.Persistence.Sql.Common/Journal/SqlJournal.cs b/src/contrib/persistence/Akka.Persistence.Sql.Common/Journal/SqlJournal.cs index bd439ef2aec..967dda87731 100644 --- a/src/contrib/persistence/Akka.Persistence.Sql.Common/Journal/SqlJournal.cs +++ b/src/contrib/persistence/Akka.Persistence.Sql.Common/Journal/SqlJournal.cs @@ -257,8 +257,9 @@ protected bool WaitingForInitialization(object message) return true; case Status.Failure fail: Log.Error(fail.Cause, "Failure during {0} initialization.", Self); - Context.Stop(Self); - return true; + + // trigger a restart so we have some hope of succeeding in the future even if initialization failed + throw new ApplicationException("Failed to initialize SQL Journal.", fail.Cause); default: Stash.Stash(); return true; diff --git a/src/contrib/persistence/Akka.Persistence.Sql.Common/Snapshot/SqlSnapshotStore.cs b/src/contrib/persistence/Akka.Persistence.Sql.Common/Snapshot/SqlSnapshotStore.cs index c2faf4f038e..8b3b86dcf95 100644 --- a/src/contrib/persistence/Akka.Persistence.Sql.Common/Snapshot/SqlSnapshotStore.cs +++ b/src/contrib/persistence/Akka.Persistence.Sql.Common/Snapshot/SqlSnapshotStore.cs @@ -137,8 +137,9 @@ private bool WaitingForInitialization(object message) return true; case Status.Failure msg: Log.Error(msg.Cause, "Error during snapshot store initialization"); - Context.Stop(Self); - return true; + + // trigger a restart so we have some hope of succeeding in the future even if initialization failed + throw new ApplicationException("Failed to initialize SQL SnapshotStore.", msg.Cause); default: Stash.Stash(); return true;