[Bug]: SQL Foreign Key Error Progress Sync #1272

Closed
opened 2026-04-24 23:38:02 +02:00 by adam · 1 comment
Owner

Originally created by @m0veax on GitHub (Jul 20, 2023).

Describe the issue

I was on vacation for 2 weeks and downloaded audiobooks to hear to my Android mobile before.

After coming back, my Mobile started syncing and my Audiobookshelf Container crashed everytime my Client connected and started syncing.

It produced the following logs:

[2023-07-20 20:56:15] INFO: [PlaybackSessionManager] Syncing local session "Tagebuch der Apokalypse 04" (play_local_17f67766-10a0-4857-a3db-61510d948027)

[2023-07-20 20:56:15] INFO: [PlaybackSessionManager] Mapped old libraryItemId "li_9rlmruluhbweysfd51" to 295d7ea4-39a0-409c-abb1-fb1db85b9d19

node:internal/process/promises:279

            triggerUncaughtException(err, true /* fromPromise */);

            ^

Error

    at Database.<anonymous> (/node_modules/sequelize/lib/dialects/sqlite/query.js:185:27)

    at /node_modules/sequelize/lib/dialects/sqlite/query.js:183:50

    at new Promise (<anonymous>)

    at Query.run (/node_modules/sequelize/lib/dialects/sqlite/query.js:183:12)

    at /node_modules/sequelize/lib/sequelize.js:315:28

    at async SQLiteQueryInterface.insert (/node_modules/sequelize/lib/dialects/abstract/query-interface.js:308:21)

    at async PlaybackSession.save (/node_modules/sequelize/lib/model.js:2490:35)

    at async Function.create (/node_modules/sequelize/lib/model.js:1362:12)

    at async PlaybackSessionManager.syncLocalSession (/server/managers/PlaybackSessionManager.js:139:7)

    at async PlaybackSessionManager.syncLocalSessionsRequest (/server/managers/PlaybackSessionManager.js:86:22) {

  name: 'SequelizeForeignKeyConstraintError',

  parent: [Error: SQLITE_CONSTRAINT: FOREIGN KEY constraint failed] {

    errno: 19,

    code: 'SQLITE_CONSTRAINT',

    sql: 'INSERT INTO `playbackSessions` (`id`,`mediaItemId`,`mediaItemType`,`displayTitle`,`displayAuthor`,`duration`,`playMethod`,`mediaPlayer`,`startTime`,`currentTime`,`serverVersion`,`coverPath`,`timeListening`,`mediaMetadata`,`extraData`,`createdAt`,`updatedAt`,`userId`,`deviceId`,`libraryId`) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20);'

  },

  original: [Error: SQLITE_CONSTRAINT: FOREIGN KEY constraint failed] {

    errno: 19,

    code: 'SQLITE_CONSTRAINT',

    sql: 'INSERT INTO `playbackSessions` (`id`,`mediaItemId`,`mediaItemType`,`displayTitle`,`displayAuthor`,`duration`,`playMethod`,`mediaPlayer`,`startTime`,`currentTime`,`serverVersion`,`coverPath`,`timeListening`,`mediaMetadata`,`extraData`,`createdAt`,`updatedAt`,`userId`,`deviceId`,`libraryId`) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20);'

  },

  sql: 'INSERT INTO `playbackSessions` (`id`,`mediaItemId`,`mediaItemType`,`displayTitle`,`displayAuthor`,`duration`,`playMethod`,`mediaPlayer`,`startTime`,`currentTime`,`serverVersion`,`coverPath`,`timeListening`,`mediaMetadata`,`extraData`,`createdAt`,`updatedAt`,`userId`,`deviceId`,`libraryId`) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20);',

  parameters: {},

  table: undefined,

  fields: undefined,

  value: undefined,

  index: undefined,

  reltype: undefined

}

I could solve my issue by deleting the App Data on my Android Phone and reconfigure the App. The server stopped crashing afterwards, because there was no sync in queue anymore

Steps to reproduce the issue

Be a while offline and listen to audiobooks I guess.

Audiobookshelf version

v2.3.1

How are you running audiobookshelf?

Docker

Originally created by @m0veax on GitHub (Jul 20, 2023). ### Describe the issue I was on vacation for 2 weeks and downloaded audiobooks to hear to my Android mobile before. After coming back, my Mobile started syncing and my Audiobookshelf Container crashed everytime my Client connected and started syncing. It produced the following logs: ``` [2023-07-20 20:56:15] INFO: [PlaybackSessionManager] Syncing local session "Tagebuch der Apokalypse 04" (play_local_17f67766-10a0-4857-a3db-61510d948027) [2023-07-20 20:56:15] INFO: [PlaybackSessionManager] Mapped old libraryItemId "li_9rlmruluhbweysfd51" to 295d7ea4-39a0-409c-abb1-fb1db85b9d19 node:internal/process/promises:279 triggerUncaughtException(err, true /* fromPromise */); ^ Error at Database.<anonymous> (/node_modules/sequelize/lib/dialects/sqlite/query.js:185:27) at /node_modules/sequelize/lib/dialects/sqlite/query.js:183:50 at new Promise (<anonymous>) at Query.run (/node_modules/sequelize/lib/dialects/sqlite/query.js:183:12) at /node_modules/sequelize/lib/sequelize.js:315:28 at async SQLiteQueryInterface.insert (/node_modules/sequelize/lib/dialects/abstract/query-interface.js:308:21) at async PlaybackSession.save (/node_modules/sequelize/lib/model.js:2490:35) at async Function.create (/node_modules/sequelize/lib/model.js:1362:12) at async PlaybackSessionManager.syncLocalSession (/server/managers/PlaybackSessionManager.js:139:7) at async PlaybackSessionManager.syncLocalSessionsRequest (/server/managers/PlaybackSessionManager.js:86:22) { name: 'SequelizeForeignKeyConstraintError', parent: [Error: SQLITE_CONSTRAINT: FOREIGN KEY constraint failed] { errno: 19, code: 'SQLITE_CONSTRAINT', sql: 'INSERT INTO `playbackSessions` (`id`,`mediaItemId`,`mediaItemType`,`displayTitle`,`displayAuthor`,`duration`,`playMethod`,`mediaPlayer`,`startTime`,`currentTime`,`serverVersion`,`coverPath`,`timeListening`,`mediaMetadata`,`extraData`,`createdAt`,`updatedAt`,`userId`,`deviceId`,`libraryId`) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20);' }, original: [Error: SQLITE_CONSTRAINT: FOREIGN KEY constraint failed] { errno: 19, code: 'SQLITE_CONSTRAINT', sql: 'INSERT INTO `playbackSessions` (`id`,`mediaItemId`,`mediaItemType`,`displayTitle`,`displayAuthor`,`duration`,`playMethod`,`mediaPlayer`,`startTime`,`currentTime`,`serverVersion`,`coverPath`,`timeListening`,`mediaMetadata`,`extraData`,`createdAt`,`updatedAt`,`userId`,`deviceId`,`libraryId`) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20);' }, sql: 'INSERT INTO `playbackSessions` (`id`,`mediaItemId`,`mediaItemType`,`displayTitle`,`displayAuthor`,`duration`,`playMethod`,`mediaPlayer`,`startTime`,`currentTime`,`serverVersion`,`coverPath`,`timeListening`,`mediaMetadata`,`extraData`,`createdAt`,`updatedAt`,`userId`,`deviceId`,`libraryId`) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20);', parameters: {}, table: undefined, fields: undefined, value: undefined, index: undefined, reltype: undefined } ``` I could solve my issue by deleting the App Data on my Android Phone and reconfigure the App. The server stopped crashing afterwards, because there was no sync in queue anymore ### Steps to reproduce the issue Be a while offline and listen to audiobooks I guess. ### Audiobookshelf version v2.3.1 ### How are you running audiobookshelf? Docker
adam added the bug label 2026-04-24 23:38:02 +02:00
adam closed this issue 2026-04-24 23:38:03 +02:00
Author
Owner

@advplyr commented on GitHub (Jul 20, 2023):

This was fixed in v2.3.2

@advplyr commented on GitHub (Jul 20, 2023): This was fixed in v2.3.2
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/audiobookshelf#1272