backstage: πŸ› Bug Report: Backend failed to start up SqliteError: database is locked

πŸ“œ Description

I try to use the sqlite database with a file and get this error:

[1] Backend failed to start up SqliteError: create table `backstage_backend_tasks__knex_migrations` (`id` integer not null primary key autoincrement, `name` varchar(255), `batch` integer, `migration_time` datetime) - database is locked
[1]     at Client_BetterSQLite3._query (/Users/Benedikt.Keil/development/github.com/otto-ec/si_backstage/src/node_modules/knex/lib/dialects/better-sqlite3/index.js:39:38)
[1]     at executeQuery (/Users/Benedikt.Keil/development/github.com/otto-ec/si_backstage/src/node_modules/knex/lib/execution/internal/query-executioner.js:37:17)
[1]     at Client_BetterSQLite3.query (/Users/Benedikt.Keil/development/github.com/otto-ec/si_backstage/src/node_modules/knex/lib/client.js:146:12)
[1]     at Runner.query (/Users/Benedikt.Keil/development/github.com/otto-ec/si_backstage/src/node_modules/knex/lib/execution/runner.js:123:36)
[1]     at Runner.queryArray (/Users/Benedikt.Keil/development/github.com/otto-ec/si_backstage/src/node_modules/knex/lib/execution/runner.js:217:21)
[1]     at ensureConnectionCallback (/Users/Benedikt.Keil/development/github.com/otto-ec/si_backstage/src/node_modules/knex/lib/execution/internal/ensure-connection-callback.js:11:19)
[1]     at Runner.ensureConnection (/Users/Benedikt.Keil/development/github.com/otto-ec/si_backstage/src/node_modules/knex/lib/execution/runner.js:300:20)
[1]     at async Runner.run (/Users/Benedikt.Keil/development/github.com/otto-ec/si_backstage/src/node_modules/knex/lib/execution/runner.js:30:19)
[1]     at async listCompleted (/Users/Benedikt.Keil/development/github.com/otto-ec/si_backstage/src/node_modules/knex/lib/migrations/migrate/migration-list-resolver.js:12:3)
[1]     at async Promise.all (index 1) {
[1]   code: 'SQLITE_BUSY'
[1] }

πŸ‘ Expected behavior

The system should start

πŸ‘Ž Actual Behavior with Screenshots

Try one of there configs

backend:
  database:
    client: better-sqlite3
    plugin:
      test:
        connection:
          directory: database
          filename: catalog.sqlite

or

backend:
  database:
    client: better-sqlite3
    connection:
      directory: database

πŸ‘Ÿ Reproduction steps

  1. Configure the database
  2. start the application

πŸ“ƒ Provide the context for the Bug.

No response

πŸ–₯️ Your Environment

No response

πŸ‘€ Have you spent some time to check if this bug has been raised before?

  • I checked and didn’t find similar issue

🏒 Have you read the Code of Conduct?

Are you willing to submit PR?

Yes I am willing to submit a PR!

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 23 (15 by maintainers)

Most upvoted comments

I set the pool max to 1 and solved it!
https://github.com/knex/knex/issues/3176

  database:
    client: better-sqlite3
    connection:
      directory: ./dbs
    knexConfig:
      pool:
        min: 0
        max: 1

came here to report the same thing on backstage 1.13.0 and adding just the GithubOrgEntityProvider entity provider, again when using sqlite not in memory. Can’t replicate with in memory sqlite.

[1] 2023-04-28T09:45:33.245Z catalog info Performing database migration type=plugin
[1] Backend failed to start up SqliteError: create table `backstage_backend_tasks__knex_migrations` (`id` integer not null primary key autoincrement, `name` varchar(255), `batch` integer, `migration_time` datetime) - database is locked
[1]     at Client_BetterSQLite3._query (/Users/msh/Documents/idp/my-backstage-app/node_modules/knex/lib/dialects/better-sqlite3/index.js:39:38)
[1]     at executeQuery (/Users/msh/Documents/idp/my-backstage-app/node_modules/knex/lib/execution/internal/query-executioner.js:37:17)
[1]     at Client_BetterSQLite3.query (/Users/msh/Documents/idp/my-backstage-app/node_modules/knex/lib/client.js:146:12)
[1]     at Runner.query (/Users/msh/Documents/idp/my-backstage-app/node_modules/knex/lib/execution/runner.js:123:36)
[1]     at Runner.queryArray (/Users/msh/Documents/idp/my-backstage-app/node_modules/knex/lib/execution/runner.js:217:21)
[1]     at ensureConnectionCallback (/Users/msh/Documents/idp/my-backstage-app/node_modules/knex/lib/execution/internal/ensure-connection-callback.js:11:19)
[1]     at Runner.ensureConnection (/Users/msh/Documents/idp/my-backstage-app/node_modules/knex/lib/execution/runner.js:300:20)
[1]     at async Runner.run (/Users/msh/Documents/idp/my-backstage-app/node_modules/knex/lib/execution/runner.js:30:19)
[1]     at async listCompleted (/Users/msh/Documents/idp/my-backstage-app/node_modules/knex/lib/migrations/migrate/migration-list-resolver.js:12:3)
[1]     at async Promise.all (index 1) {
[1]   code: 'SQLITE_BUSY'
[1] }

Could it be that you are missing an await on a promise when creating those scheduled providers? Such that it tries to run two migrations at the same time.

I’ll add here too, that we don’t officially support file based sqlite. The entire driver was originally only intended for quick and dirty in-memory local dev and testing use. The only officially supported drivers are postgres, and in-memory sqlite. If you or others in the community find bugs with the use of on-disk sqlite and fix them, we’re of course super happy to keep up that best-effort support and help get those pull requests merged.