Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle "database is locked" error when writing to cache database #346

Closed
Tracked by #318
mscottford opened this issue Oct 19, 2022 · 0 comments · Fixed by #369
Closed
Tracked by #318

Handle "database is locked" error when writing to cache database #346

mscottford opened this issue Oct 19, 2022 · 0 comments · Fixed by #369
Assignees
Labels
bug Something isn't working
Milestone

Comments

@mscottford
Copy link
Member

This can be triggered whenever SaveChanges is called. With so many threads writing to the database, we should implement an incremental backoff and wait strategy if this exception is thrown. The Polly library can help with that implementation.

Stacktrace:

Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while saving the entity changes. See the inner exception for details.
 ---> Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 5: 'database is locked'.
   at Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(Int32 rc, sqlite3 db)
   at Microsoft.Data.Sqlite.SqliteDataReader.NextResult()
   at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader(CommandBehavior behavior)
   at Microsoft.Data.Sqlite.SqliteCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.ExecuteReader()
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject)
   at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)
   --- End of inner exception stack trace ---
   at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)
   at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(IEnumerable`1 commandBatches, IRelationalConnection connection)
   at Microsoft.EntityFrameworkCore.Storage.RelationalDatabase.SaveChanges(IList`1 entries)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(IList`1 entriesToSave)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(StateManager stateManager, Boolean acceptAllChangesOnSuccess)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.<>c.<SaveChanges>b__107_0(DbContext _, ValueTuple`2 t)
   at Microsoft.EntityFrameworkCore.Storage.NonRetryingExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)
   at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)
   at Microsoft.EntityFrameworkCore.DbContext.SaveChanges()
   at Corgibytes.Freshli.Cli.Functionality.CacheDb.AddPackageLibYear(CachedPackageLibYear packageLibYear) in /Users/mscottford/code/freshli/freshli-cli/Corgibytes.Freshli.Cli/Functionality/CacheDb.cs:line 47
   at Corgibytes.Freshli.Cli.Functionality.LibYear.ComputeLibYearForPackageActivity.Handle(IApplicationEventEngine eventClient) in /Users/mscottford/code/freshli/freshli-cli/Corgibytes.Freshli.Cli/Functionality/LibYear/ComputeLibYearForPackageActivity.cs:line 29
   at Corgibytes.Freshli.Cli.Functionality.Engine.ApplicationEngine.HandleActivity(IApplicationActivity activity) in /Users/mscottford/code/freshli/freshli-cli/Corgibytes.Freshli.Cli/Functionality/Engine/ApplicationEngine.cs:line 140
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants