Jellyfin Forum
SQLite Error: database is locked - Printable Version

+- Jellyfin Forum (https://forum.jellyfin.org)
+-- Forum: Support (https://forum.jellyfin.org/f-support)
+--- Forum: Troubleshooting (https://forum.jellyfin.org/f-troubleshooting)
+--- Thread: SQLite Error: database is locked (/t-sqlite-error-database-is-locked)



SQLite Error: database is locked - happyvoid - 2024-06-11

After using SynoCommunity packager for a few years with 10.8 running ok, after runnnig into issues with 10.9 switched to Docker setup on a Synology 218+.

This is a new setup using the following docker_compose.yml file:

Code:
services:
  jellyfin:
    container_name: jellyfin
    image: jellyfin/jellyfin
    ports:
      - "8096:8096"
    environment:
      - PUID=UID_GOES_HERE (this is the actual UID)
      - PGID=100
      - UMASK=002
      - TZ=Europe/Berlin
    volumes:
      - /volume1/docker/jellyfin:/config
      - /volume1/Share1:/Share1:ro
      - /volume1/Share2:/Share2ro
      - /volume1/Share3:/Share3:ro
    devices:
      - /dev/dri:/dev/dri

Added folders from the three different shares to Library. Let Jellyfin sit, scan and do it's thing for a few days.

It seems scans and Audio Normalisation have finished. But whenever trying to access Jellyfin there is a lot of audible accessing going on on the NAS to the point where everything seems to lockup (two hhds on a 218+, no NVMe). Clicking menu items e.g. like Scheduled Tasks just shows the spinner and no info ever loads. Same is true trying to access home. Sometimes the items load, but it is slow to a point where the library is not usable.

Looking at the logs, database is locked does not sound great:

Code:
[2024-06-11 06:23:54.110 +02:00] [ERR] [279] Jellyfin.Api.Middleware.ExceptionMiddleware: Error processing request. URL "POST" "/Users/AuthenticateByName".
Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 5: 'database is locked'.
  at Microsoft.Data.Sqlite.SqliteDataReader.NextResult()
  at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader(CommandBehavior behavior)
  at Microsoft.Data.Sqlite.SqliteConnectionExtensions.ExecuteNonQuery(SqliteConnection connection, String commandText, SqliteParameter[] parameters)
  at Microsoft.Data.Sqlite.SqliteTransaction..ctor(SqliteConnection connection, IsolationLevel isolationLevel, Boolean deferred)
  at System.Data.Common.DbConnection.BeginDbTransactionAsync(IsolationLevel isolationLevel, CancellationToken cancellationToken)
--- End of stack trace from previous location ---

More log: https://bin.disroot.org/?ce008bc32593b7a2#JB6MnkFTsFkSoeJRe8YxGKpnGGSaA5tZkTSeDgtnf98N (1 month)

Was unsure about
Code:
[2024-06-11 06:13:45.194 +02:00] [INF] [257] Jellyfin.Api.Auth.CustomAuthenticationHandler: "CustomAuthentication" was not authenticated. Failure message: "Invalid token."
so tried logging out the old login on some devices and setting up the server and user again.

Any idea what I am doing wrong or why the NAS chokes up? I know this isn't an ideal setup performance wise. But in the past this worked on acceptable level using v10.8 and the SynoCommunity package.


RE: SQLite Error: database is locked - crobibero - 2024-06-11

Please upgrade to 10.9.6. If you are already on 10.9.6 we would need a full log, not just the exception.


RE: SQLite Error: database is locked - happyvoid - 2024-06-11

Thanks for taking a look. This is 10.9.6.

Full log: https://bin.disroot.org/?4db311bd04dfb923#7pxcRt2nSSgMLi3uSApFG1pwuBcQ76Rmbr6B7DQKr3VG

There's some logging in going on as I migrated client apps to the new server on a few devices.


RE: SQLite Error: database is locked - pcm - 2024-06-11

I kept having this *exactly same* issue too. I had (have) this issue on 1.9.2 and 1.9.3 (my current) and I had to change "Parallel library scan tasks limit" to 1 (it's 0 by default, which will set the number of scans to number of cpu-threads your computer can run).
And that fixed the issue for me because now there is only one thread doing the library scan and writing to library.db file and hence no way to do get into a race condition/deadlock ... Not the most performant solution but got the job done for me. Be aware that your scans will take a lot longer but they'll complete guaranteed.
You can find 'Parallel library scan tasks limit' config setting under "general" section in your admin-dashboard.


RE: SQLite Error: database is locked - happyvoid - 2024-06-14

Thanks for sharing your suggestion to change Parallel library scan tasks limit to 1. I tried that, while it may have helped, it did not resolve the overall slowness I was encountering.

What did help was setting an environment variable for the docker container:

1. stopped the docker project
2. in the environment: section of the docker-compose-yml file I added the line - JELLYFIN_SQLITE__disableSecondLevelCache=true
3. re-build docker project

This did help and Jellyfin was in usable state for a while.

Currently though I am again seeing the problematic errors in the log, so I was wrong thinking this was no longer a problem and sadly both the change for scan tasks and the env var did not resolve the issue:


[2024-06-14 10:34:07.742 +02:00] [ERR] [96] Microsoft.EntityFrameworkCore.Update: An exception occurred in the database while saving changes for context type '"Jellyfin.Server.Implementations.JellyfinDbContext"'."
""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.SqliteDataReader.NextResult()
  at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader(CommandBehavior behavior)
  at Microsoft.Data.Sqlite.SqliteCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
  at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
  at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
  at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.ExecuteAsync(IRelationalConnection connection, CancellationToken cancellationToken)
  --- End of inner exception stack trace ---
  at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.ExecuteAsync(IRelationalConnection connection, CancellationToken cancellationToken)
  at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.ExecuteAsync(IEnumerable
1 commandBatches, IRelationalConnection connection, CancellationToken cancellationToken)
  at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.ExecuteAsync(IEnumerable1 commandBatches, IRelationalConnection connection, CancellationToken cancellationToken)
  at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.ExecuteAsync(IEnumerable
1 commandBatches, IRelationalConnection connection, CancellationToken cancellationToken)
  at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(IList1 entriesToSave, CancellationToken cancellationToken)
  at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(StateManager stateManager, Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
  at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)"



RE: SQLite Error: database is locked - gnattu - 2024-06-14

More likely you will need https://github.com/jellyfin/jellyfin/pull/11901 merged for your issue as 2nd level cache works badly for your setup and need a device cache to be implemented separately.