LiteDB Transaction Error

A couple of times lately I’ve managed to tie PSU up into a knot. Running a script or making other random changes just flashes up the “error” toast, and the log has an exception like this:

2021-12-20 23:39:32.926 +00:00 [ERR] An unhandled exception has occurred while executing the request.
System.Exception: LiteDB ENSURE: transaction must be active to rollback (current state: Disposed)
at LiteDB.Constants.ENSURE(Boolean conditional, String message)
at LiteDB.Engine.TransactionService.Rollback()
at LiteDB.Engine.LiteEngine.AutoTransaction[T](Func2 fn) at LiteDB.LiteCollection1.Insert(T entity)
at LiteDB.LiteRepository.Insert[T](T entity, String collectionName)
at UniversalAutomation.LiteDBTable`1.Insert(T item) in D:\a\universal\universal\src\UniversalAutomation.LiteDBv5\LiteDBDatabase.cs:line 509
at Universal.Server.Services.UniversalClient.InvokeScript(JobContext jobContext) in D:\a\universal\universal\src\Universal.Server\Services\UniversalClient.cs:line 278

The only fix I’ve found is to rename the database-log.db file and restart the app.

Is this a known issue? Something related to Azure hosting, or something I’m doing wrong?

Cheers,
Matt

Product: PowerShell Universal
Version: 2.6.2

I’ve seen this reported outside of Azure but the exception was kind of different but related to LiteDB. I’ve never heard of it continuing it happen. I’ll have to open an issue for this and investigate.

Hit the same thing in our Azure hosted instance a few times recently - seems to happen after fiddling with scripts.

Blowing it away and rebuilding sorted it a couple of times last week, but I did a full destroy and rebuild last night and it’s come back with the same error.

Going to try another rebuild, but this is the full log if it’s at all useful (v2.7.3) :

[09:16:07 INF] Azure Web Sites environment detected. Using 'C:\home\ASP.NET\DataProtection-Keys' as key repository; keys will not be encrypted at rest.
Unhandled exception. System.Exception: LiteDB ENSURE: transaction must be active to rollback (current state: Disposed)
   at LiteDB.Constants.ENSURE(Boolean conditional, String message)
   at LiteDB.Engine.TransactionService.Rollback()
   at LiteDB.Engine.LiteEngine.AutoTransaction[T](Func`2 fn)
   at LiteDB.Engine.LiteEngine.EnsureIndex(String collection, String name, BsonExpression expression, Boolean unique)
   at LiteDB.LiteCollection`1.EnsureIndex(String name, BsonExpression expression, Boolean unique)
   at UniversalAutomation.LiteDBv5Database.SetupTables() in D:\a\universal\universal\src\UniversalAutomation.LiteDBv5\LiteDBDatabase.cs:line 135
   at UniversalAutomation.LiteDBv5Database..ctor(IServiceProvider serviceProvider, String connectionString) in D:\a\universal\universal\src\UniversalAutomation.LiteDBv5\LiteDBDatabase.cs:line 59
   at UniversalAutomation.LiteDBv5.DatabaseFeature.GetDatabase(IServiceProvider serviceProvider, String connectionString) in D:\a\universal\universal\src\UniversalAutomation.LiteDBv5\Plugin.cs:line 40
   at Universal.Server.Services.PluginService.<>c__DisplayClass3_0.<AddDatabase>b__2(IServiceProvider x) in D:\a\universal\universal\src\Universal.Server\Services\PluginService.cs:line 99
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitIEnumerable(IEnumerableCallSite enumerableCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitNoCache(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider)
   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
   at Universal.Server.Program.<>c__DisplayClass3_0.<Main>b__0(Options o) in D:\a\universal\universal\src\Universal.Server\Program.cs:line 55
   at CommandLine.ParserResultExtensions.WithParsed[T](ParserResult`1 result, Action`1 action)
   at Universal.Server.Program.Main(String[] args) in D:\a\universal\universal\src\Universal.Server\Program.cs:line 43

@TheAlbionist Check out this thread, which turned into kind of a duplicate of this one:

Script Jobs stuck on “Canceling” - PowerShell Universal - Ironman Software Forums

I’ll be interested to hear whether the change Adam made to the connection string works for you. It didn’t work for me.

1 Like