diff --git a/src/persistence/Elsa.Persistence.YesSql/Services/DataMigrationManager.cs b/src/persistence/Elsa.Persistence.YesSql/Services/DataMigrationManager.cs index 4c75b28c2..bcd714e9d 100644 --- a/src/persistence/Elsa.Persistence.YesSql/Services/DataMigrationManager.cs +++ b/src/persistence/Elsa.Persistence.YesSql/Services/DataMigrationManager.cs @@ -53,6 +53,25 @@ namespace Elsa.Persistence.YesSql.Services _logger.LogError(ex, "Could not run migrations automatically on '{FeatureName}'", migration); } } + + try + { + var commitTask = _session.CurrentTransaction?.CommitAsync() ?? Task.CompletedTask; + await commitTask; + } + catch(InvalidOperationException) + { + // TODO: Improve on this ugly hack/workaround! + // + // The commit can throw this exception because it's already been committed. But if + // we don't explicitly commit here then it never gets committed and it's as if the + // migrations never took place! + // + // I suspect that either this method is being called more than once, or perhaps (IMO + // more likely) an async operation (somewhere) isn't being awaited. That could mean + // that the connection is closed/killed-off before the commit actually completes, + // with the effect that it doesn't happen. + } } public async Task> GetMigrationsThatNeedUpdateAsync()