[Bug]: Server crash on Foreign Key constraint failure #2531

Closed
opened 2026-04-25 00:08:04 +02:00 by adam · 4 comments
Owner

Originally created by @smithmd on GitHub (Jan 28, 2025).

What happened?

The server stopped serving.

What did you expect to happen?

I expect the server to not crash.

Steps to reproduce the issue

  1. Really not sure what caused it, so I don't know how to reproduce. It was working, then it wasn't.

Audiobookshelf version

v2.18.1

How are you running audiobookshelf?

Docker

What OS is your Audiobookshelf server hosted from?

macOS

If the issue is being seen in the UI, what browsers are you seeing the problem on?

None

Logs

2025-01-27 20:42:08 audiobookshelf-1  | [2025-01-27 20:42:08.796] FATAL: [Server] Unhandled rejection: Error
2025-01-27 20:42:08 audiobookshelf-1  |     at Database.<anonymous> (/node_modules/sequelize/lib/dialects/sqlite/query.js:185:27)
2025-01-27 20:42:08 audiobookshelf-1  |     at /node_modules/sequelize/lib/dialects/sqlite/query.js:183:50
2025-01-27 20:42:08 audiobookshelf-1  |     at new Promise (<anonymous>)
2025-01-27 20:42:08 audiobookshelf-1  |     at Query.run (/node_modules/sequelize/lib/dialects/sqlite/query.js:183:12)
2025-01-27 20:42:08 audiobookshelf-1  |     at /node_modules/sequelize/lib/sequelize.js:315:28
2025-01-27 20:42:08 audiobookshelf-1  |     at async SQLiteQueryInterface.insert (/node_modules/sequelize/lib/dialects/abstract/query-interface.js:308:21)
2025-01-27 20:42:08 audiobookshelf-1  |     at async MediaProgress.save (/node_modules/sequelize/lib/model.js:2490:35)
2025-01-27 20:42:08 audiobookshelf-1  |     at async mediaProgress.create (/node_modules/sequelize/lib/model.js:1362:12)
2025-01-27 20:42:08 audiobookshelf-1  |     at async User.createUpdateMediaProgressFromPayload (/server/models/User.js:708:23)
2025-01-27 20:42:08 audiobookshelf-1  |     at async ApiRouter.createUpdateMediaProgress (/server/controllers/MeController.js:148:35) {
2025-01-27 20:42:08 audiobookshelf-1  |   name: 'SequelizeForeignKeyConstraintError',
2025-01-27 20:42:08 audiobookshelf-1  |   parent: [Error: SQLITE_CONSTRAINT: FOREIGN KEY constraint failed] {
2025-01-27 20:42:08 audiobookshelf-1  |     errno: 19,
2025-01-27 20:42:08 audiobookshelf-1  |     code: 'SQLITE_CONSTRAINT',
2025-01-27 20:42:08 audiobookshelf-1  |     sql: 'INSERT INTO `mediaProgresses` (`id`,`mediaItemId`,`mediaItemType`,`duration`,`currentTime`,`isFinished`,`hideFromContinueListening`,`ebookLocation`,`ebookProgress`,`finishedAt`,`extraData`,`createdAt`,`updatedAt`,`userId`) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14);'
2025-01-27 20:42:08 audiobookshelf-1  |   },
2025-01-27 20:42:08 audiobookshelf-1  |   original: [Error: SQLITE_CONSTRAINT: FOREIGN KEY constraint failed] {
2025-01-27 20:42:08 audiobookshelf-1  |     errno: 19,
2025-01-27 20:42:08 audiobookshelf-1  |     code: 'SQLITE_CONSTRAINT',
2025-01-27 20:42:08 audiobookshelf-1  |     sql: 'INSERT INTO `mediaProgresses` (`id`,`mediaItemId`,`mediaItemType`,`duration`,`currentTime`,`isFinished`,`hideFromContinueListening`,`ebookLocation`,`ebookProgress`,`finishedAt`,`extraData`,`createdAt`,`updatedAt`,`userId`) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14);'
2025-01-27 20:42:08 audiobookshelf-1  |   },
2025-01-27 20:42:08 audiobookshelf-1  |   sql: 'INSERT INTO `mediaProgresses` (`id`,`mediaItemId`,`mediaItemType`,`duration`,`currentTime`,`isFinished`,`hideFromContinueListening`,`ebookLocation`,`ebookProgress`,`finishedAt`,`extraData`,`createdAt`,`updatedAt`,`userId`) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14);',
2025-01-27 20:42:08 audiobookshelf-1  |   parameters: {},
2025-01-27 20:42:08 audiobookshelf-1  |   table: undefined,
2025-01-27 20:42:08 audiobookshelf-1  |   fields: undefined,
2025-01-27 20:42:08 audiobookshelf-1  |   value: undefined,
2025-01-27 20:42:08 audiobookshelf-1  |   index: undefined,
2025-01-27 20:42:08 audiobookshelf-1  |   reltype: undefined
2025-01-27 20:42:08 audiobookshelf-1  | } 
2025-01-27 20:42:08 audiobookshelf-1  | promise: Promise {
2025-01-27 20:42:08 audiobookshelf-1  |   <rejected> Error
2025-01-27 20:42:08 audiobookshelf-1  |       at Database.<anonymous> (/node_modules/sequelize/lib/dialects/sqlite/query.js:185:27)
2025-01-27 20:42:08 audiobookshelf-1  |       at /node_modules/sequelize/lib/dialects/sqlite/query.js:183:50
2025-01-27 20:42:08 audiobookshelf-1  |       at new Promise (<anonymous>)
2025-01-27 20:42:08 audiobookshelf-1  |       at Query.run (/node_modules/sequelize/lib/dialects/sqlite/query.js:183:12)
2025-01-27 20:42:08 audiobookshelf-1  |       at /node_modules/sequelize/lib/sequelize.js:315:28
2025-01-27 20:42:08 audiobookshelf-1  |       at async SQLiteQueryInterface.insert (/node_modules/sequelize/lib/dialects/abstract/query-interface.js:308:21)
2025-01-27 20:42:08 audiobookshelf-1  |       at async MediaProgress.save (/node_modules/sequelize/lib/model.js:2490:35)
2025-01-27 20:42:08 audiobookshelf-1  |       at async mediaProgress.create (/node_modules/sequelize/lib/model.js:1362:12)
2025-01-27 20:42:08 audiobookshelf-1  |       at async User.createUpdateMediaProgressFromPayload (/server/models/User.js:708:23)
2025-01-27 20:42:08 audiobookshelf-1  |       at async ApiRouter.createUpdateMediaProgress (/server/controllers/MeController.js:148:35) {
2025-01-27 20:42:08 audiobookshelf-1  |     name: 'SequelizeForeignKeyConstraintError',
2025-01-27 20:42:08 audiobookshelf-1  |     parent: [Error: SQLITE_CONSTRAINT: FOREIGN KEY constraint failed] {
2025-01-27 20:42:08 audiobookshelf-1  |       errno: 19,
2025-01-27 20:42:08 audiobookshelf-1  |       code: 'SQLITE_CONSTRAINT',
2025-01-27 20:42:08 audiobookshelf-1  |       sql: 'INSERT INTO `mediaProgresses` (`id`,`mediaItemId`,`mediaItemType`,`duration`,`currentTime`,`isFinished`,`hideFromContinueListening`,`ebookLocation`,`ebookProgress`,`finishedAt`,`extraData`,`createdAt`,`updatedAt`,`userId`) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14);'
2025-01-27 20:42:08 audiobookshelf-1  |     },
2025-01-27 20:42:08 audiobookshelf-1  |     original: [Error: SQLITE_CONSTRAINT: FOREIGN KEY constraint failed] {
2025-01-27 20:42:08 audiobookshelf-1  |       errno: 19,
2025-01-27 20:42:08 audiobookshelf-1  |       code: 'SQLITE_CONSTRAINT',
2025-01-27 20:42:08 audiobookshelf-1  |       sql: 'INSERT INTO `mediaProgresses` (`id`,`mediaItemId`,`mediaItemType`,`duration`,`currentTime`,`isFinished`,`hideFromContinueListening`,`ebookLocation`,`ebookProgress`,`finishedAt`,`extraData`,`createdAt`,`updatedAt`,`userId`) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14);'
2025-01-27 20:42:08 audiobookshelf-1  |     },
2025-01-27 20:42:08 audiobookshelf-1  |     sql: 'INSERT INTO `mediaProgresses` (`id`,`mediaItemId`,`mediaItemType`,`duration`,`currentTime`,`isFinished`,`hideFromContinueListening`,`ebookLocation`,`ebookProgress`,`finishedAt`,`extraData`,`createdAt`,`updatedAt`,`userId`) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14);',
2025-01-27 20:42:08 audiobookshelf-1  |     parameters: {},
2025-01-27 20:42:08 audiobookshelf-1  |     table: undefined,
2025-01-27 20:42:08 audiobookshelf-1  |     fields: undefined,
2025-01-27 20:42:08 audiobookshelf-1  |     value: undefined,
2025-01-27 20:42:08 audiobookshelf-1  |     index: undefined,
2025-01-27 20:42:08 audiobookshelf-1  |     reltype: undefined
2025-01-27 20:42:08 audiobookshelf-1  |   }
2025-01-27 20:42:08 audiobookshelf-1  | }

Additional Notes

No response

Originally created by @smithmd on GitHub (Jan 28, 2025). ### What happened? The server stopped serving. ### What did you expect to happen? I expect the server to not crash. ### Steps to reproduce the issue 1. Really not sure what caused it, so I don't know how to reproduce. It was working, then it wasn't. ### Audiobookshelf version v2.18.1 ### How are you running audiobookshelf? Docker ### What OS is your Audiobookshelf server hosted from? macOS ### If the issue is being seen in the UI, what browsers are you seeing the problem on? None ### Logs ```shell 2025-01-27 20:42:08 audiobookshelf-1 | [2025-01-27 20:42:08.796] FATAL: [Server] Unhandled rejection: Error 2025-01-27 20:42:08 audiobookshelf-1 | at Database.<anonymous> (/node_modules/sequelize/lib/dialects/sqlite/query.js:185:27) 2025-01-27 20:42:08 audiobookshelf-1 | at /node_modules/sequelize/lib/dialects/sqlite/query.js:183:50 2025-01-27 20:42:08 audiobookshelf-1 | at new Promise (<anonymous>) 2025-01-27 20:42:08 audiobookshelf-1 | at Query.run (/node_modules/sequelize/lib/dialects/sqlite/query.js:183:12) 2025-01-27 20:42:08 audiobookshelf-1 | at /node_modules/sequelize/lib/sequelize.js:315:28 2025-01-27 20:42:08 audiobookshelf-1 | at async SQLiteQueryInterface.insert (/node_modules/sequelize/lib/dialects/abstract/query-interface.js:308:21) 2025-01-27 20:42:08 audiobookshelf-1 | at async MediaProgress.save (/node_modules/sequelize/lib/model.js:2490:35) 2025-01-27 20:42:08 audiobookshelf-1 | at async mediaProgress.create (/node_modules/sequelize/lib/model.js:1362:12) 2025-01-27 20:42:08 audiobookshelf-1 | at async User.createUpdateMediaProgressFromPayload (/server/models/User.js:708:23) 2025-01-27 20:42:08 audiobookshelf-1 | at async ApiRouter.createUpdateMediaProgress (/server/controllers/MeController.js:148:35) { 2025-01-27 20:42:08 audiobookshelf-1 | name: 'SequelizeForeignKeyConstraintError', 2025-01-27 20:42:08 audiobookshelf-1 | parent: [Error: SQLITE_CONSTRAINT: FOREIGN KEY constraint failed] { 2025-01-27 20:42:08 audiobookshelf-1 | errno: 19, 2025-01-27 20:42:08 audiobookshelf-1 | code: 'SQLITE_CONSTRAINT', 2025-01-27 20:42:08 audiobookshelf-1 | sql: 'INSERT INTO `mediaProgresses` (`id`,`mediaItemId`,`mediaItemType`,`duration`,`currentTime`,`isFinished`,`hideFromContinueListening`,`ebookLocation`,`ebookProgress`,`finishedAt`,`extraData`,`createdAt`,`updatedAt`,`userId`) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14);' 2025-01-27 20:42:08 audiobookshelf-1 | }, 2025-01-27 20:42:08 audiobookshelf-1 | original: [Error: SQLITE_CONSTRAINT: FOREIGN KEY constraint failed] { 2025-01-27 20:42:08 audiobookshelf-1 | errno: 19, 2025-01-27 20:42:08 audiobookshelf-1 | code: 'SQLITE_CONSTRAINT', 2025-01-27 20:42:08 audiobookshelf-1 | sql: 'INSERT INTO `mediaProgresses` (`id`,`mediaItemId`,`mediaItemType`,`duration`,`currentTime`,`isFinished`,`hideFromContinueListening`,`ebookLocation`,`ebookProgress`,`finishedAt`,`extraData`,`createdAt`,`updatedAt`,`userId`) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14);' 2025-01-27 20:42:08 audiobookshelf-1 | }, 2025-01-27 20:42:08 audiobookshelf-1 | sql: 'INSERT INTO `mediaProgresses` (`id`,`mediaItemId`,`mediaItemType`,`duration`,`currentTime`,`isFinished`,`hideFromContinueListening`,`ebookLocation`,`ebookProgress`,`finishedAt`,`extraData`,`createdAt`,`updatedAt`,`userId`) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14);', 2025-01-27 20:42:08 audiobookshelf-1 | parameters: {}, 2025-01-27 20:42:08 audiobookshelf-1 | table: undefined, 2025-01-27 20:42:08 audiobookshelf-1 | fields: undefined, 2025-01-27 20:42:08 audiobookshelf-1 | value: undefined, 2025-01-27 20:42:08 audiobookshelf-1 | index: undefined, 2025-01-27 20:42:08 audiobookshelf-1 | reltype: undefined 2025-01-27 20:42:08 audiobookshelf-1 | } 2025-01-27 20:42:08 audiobookshelf-1 | promise: Promise { 2025-01-27 20:42:08 audiobookshelf-1 | <rejected> Error 2025-01-27 20:42:08 audiobookshelf-1 | at Database.<anonymous> (/node_modules/sequelize/lib/dialects/sqlite/query.js:185:27) 2025-01-27 20:42:08 audiobookshelf-1 | at /node_modules/sequelize/lib/dialects/sqlite/query.js:183:50 2025-01-27 20:42:08 audiobookshelf-1 | at new Promise (<anonymous>) 2025-01-27 20:42:08 audiobookshelf-1 | at Query.run (/node_modules/sequelize/lib/dialects/sqlite/query.js:183:12) 2025-01-27 20:42:08 audiobookshelf-1 | at /node_modules/sequelize/lib/sequelize.js:315:28 2025-01-27 20:42:08 audiobookshelf-1 | at async SQLiteQueryInterface.insert (/node_modules/sequelize/lib/dialects/abstract/query-interface.js:308:21) 2025-01-27 20:42:08 audiobookshelf-1 | at async MediaProgress.save (/node_modules/sequelize/lib/model.js:2490:35) 2025-01-27 20:42:08 audiobookshelf-1 | at async mediaProgress.create (/node_modules/sequelize/lib/model.js:1362:12) 2025-01-27 20:42:08 audiobookshelf-1 | at async User.createUpdateMediaProgressFromPayload (/server/models/User.js:708:23) 2025-01-27 20:42:08 audiobookshelf-1 | at async ApiRouter.createUpdateMediaProgress (/server/controllers/MeController.js:148:35) { 2025-01-27 20:42:08 audiobookshelf-1 | name: 'SequelizeForeignKeyConstraintError', 2025-01-27 20:42:08 audiobookshelf-1 | parent: [Error: SQLITE_CONSTRAINT: FOREIGN KEY constraint failed] { 2025-01-27 20:42:08 audiobookshelf-1 | errno: 19, 2025-01-27 20:42:08 audiobookshelf-1 | code: 'SQLITE_CONSTRAINT', 2025-01-27 20:42:08 audiobookshelf-1 | sql: 'INSERT INTO `mediaProgresses` (`id`,`mediaItemId`,`mediaItemType`,`duration`,`currentTime`,`isFinished`,`hideFromContinueListening`,`ebookLocation`,`ebookProgress`,`finishedAt`,`extraData`,`createdAt`,`updatedAt`,`userId`) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14);' 2025-01-27 20:42:08 audiobookshelf-1 | }, 2025-01-27 20:42:08 audiobookshelf-1 | original: [Error: SQLITE_CONSTRAINT: FOREIGN KEY constraint failed] { 2025-01-27 20:42:08 audiobookshelf-1 | errno: 19, 2025-01-27 20:42:08 audiobookshelf-1 | code: 'SQLITE_CONSTRAINT', 2025-01-27 20:42:08 audiobookshelf-1 | sql: 'INSERT INTO `mediaProgresses` (`id`,`mediaItemId`,`mediaItemType`,`duration`,`currentTime`,`isFinished`,`hideFromContinueListening`,`ebookLocation`,`ebookProgress`,`finishedAt`,`extraData`,`createdAt`,`updatedAt`,`userId`) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14);' 2025-01-27 20:42:08 audiobookshelf-1 | }, 2025-01-27 20:42:08 audiobookshelf-1 | sql: 'INSERT INTO `mediaProgresses` (`id`,`mediaItemId`,`mediaItemType`,`duration`,`currentTime`,`isFinished`,`hideFromContinueListening`,`ebookLocation`,`ebookProgress`,`finishedAt`,`extraData`,`createdAt`,`updatedAt`,`userId`) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14);', 2025-01-27 20:42:08 audiobookshelf-1 | parameters: {}, 2025-01-27 20:42:08 audiobookshelf-1 | table: undefined, 2025-01-27 20:42:08 audiobookshelf-1 | fields: undefined, 2025-01-27 20:42:08 audiobookshelf-1 | value: undefined, 2025-01-27 20:42:08 audiobookshelf-1 | index: undefined, 2025-01-27 20:42:08 audiobookshelf-1 | reltype: undefined 2025-01-27 20:42:08 audiobookshelf-1 | } 2025-01-27 20:42:08 audiobookshelf-1 | } ``` ### Additional Notes _No response_
adam added the bug label 2026-04-25 00:08:04 +02:00
adam closed this issue 2026-04-25 00:08:04 +02:00
Author
Owner

@smithmd commented on GitHub (Jan 28, 2025):

Sorry about the lack of detail here. I just don't know what to say other than what I saw in the logs when I restarted the server in docker.

Edit: I should maybe add that this was a new install restored from backup. Also, the backup didn't restore any of the podcast feed URLs so I had to fix those manually. Not sure if related.

@smithmd commented on GitHub (Jan 28, 2025): Sorry about the lack of detail here. I just don't know what to say other than what I saw in the logs when I restarted the server in docker. Edit: I should maybe add that this was a new install restored from backup. Also, the backup didn't restore any of the podcast feed URLs so I had to fix those manually. Not sure if related.
Author
Owner

@advplyr commented on GitHub (Jan 28, 2025):

Is this continuing to happen or was this one time and the server is working fine?

@advplyr commented on GitHub (Jan 28, 2025): Is this continuing to happen or was this one time and the server is working fine?
Author
Owner

@smithmd commented on GitHub (Jan 30, 2025):

It was just a one-time thing so far. Seems to have stopped happening so maybe something happened that made the bad data fix itself.

@smithmd commented on GitHub (Jan 30, 2025): It was just a one-time thing so far. Seems to have stopped happening so maybe something happened that made the bad data fix itself.
Author
Owner

@advplyr commented on GitHub (Jan 30, 2025):

Thanks we'll re-open if we can get something reproducible

@advplyr commented on GitHub (Jan 30, 2025): Thanks we'll re-open if we can get something reproducible
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/audiobookshelf#2531