[Bug]: More than one offline session result in a uniqe constraint violation crash on the next time the app connects to the server #1514

Closed
opened 2026-04-24 23:48:18 +02:00 by adam · 3 comments
Owner

Originally created by @Gorasa on GitHub (Nov 7, 2023).

Describe the issue

If there is more thanone listening session in offline mode, the Server will crash on the app becomming online again, with the cause
Error: SQLITE_CONSTRAINT: UNIQUE constraint failed: playbackSessions.id

Error log part 1:

parent: [Error: SQLITE_CONSTRAINT: UNIQUE constraint failed: playbackSessions.id] {
    errno: 19,
    code: 'SQLITE_CONSTRAINT',
    sql: 'INSERT INTO `playbackSessions` (`id`,`mediaItemId`,`mediaItemType`,`displayTitle`,`displayAuthor`,`duration`,`playMethod`,`mediaPlayer`,`startTime`,`currentTime`,`serverVersion`,`coverPath`,`timeListening`,`mediaMetadata`,`date`,`dayOfWeek`,`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,$21,$22);'
  },
  original: [Error: SQLITE_CONSTRAINT: UNIQUE constraint failed: playbackSessions.id] {
    errno: 19,
    code: 'SQLITE_CONSTRAINT',
    sql: 'INSERT INTO `playbackSessions` (`id`,`mediaItemId`,`mediaItemType`,`displayTitle`,`displayAuthor`,`duration`,`playMethod`,`mediaPlayer`,`startTime`,`currentTime`,`serverVersion`,`coverPath`,`timeListening`,`mediaMetadata`,`date`,`dayOfWeek`,`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,$21,$22);'
  },
  fields: [ 'id' ],
  sql: 'INSERT INTO `playbackSessions` (`id`,`mediaItemId`,`mediaItemType`,`displayTitle`,`displayAuthor`,`duration`,`playMethod`,`mediaPlayer`,`startTime`,`currentTime`,`serverVersion`,`coverPath`,`timeListening`,`mediaMetadata`,`date`,`dayOfWeek`,`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,$21,$22);'
}

Error log part 2:

 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:142:7)
    at async PlaybackSessionManager.syncLocalSessionRequest (/server/managers/PlaybackSessionManager.js:192:20) {
  name: 'SequelizeUniqueConstraintError',
  errors: [
    ValidationErrorItem {
      message: 'id must be unique',
      type: 'unique violation',
      path: 'id',
      value: '54396192-ebfd-4107-ab68-7ea351d572ea',
      origin: 'DB',
      instance: playbackSession {
        dataValues: { 

Steps to reproduce the issue

  1. Move away from your server (no connection to the server)
  2. Listen to an audiobook on your way to work
  3. Listen to an audiobook on your way from work
  4. return to your home wifi
  5. server crashes, becuase all listening sessions of the day will get the same id

Audiobookshelf version

v2.5.0

How are you running audiobookshelf?

Docker

Originally created by @Gorasa on GitHub (Nov 7, 2023). ### Describe the issue If there is more thanone listening session in offline mode, the Server will crash on the app becomming online again, with the cause `Error: SQLITE_CONSTRAINT: UNIQUE constraint failed: playbackSessions.id` Error log part 1: ``` parent: [Error: SQLITE_CONSTRAINT: UNIQUE constraint failed: playbackSessions.id] { errno: 19, code: 'SQLITE_CONSTRAINT', sql: 'INSERT INTO `playbackSessions` (`id`,`mediaItemId`,`mediaItemType`,`displayTitle`,`displayAuthor`,`duration`,`playMethod`,`mediaPlayer`,`startTime`,`currentTime`,`serverVersion`,`coverPath`,`timeListening`,`mediaMetadata`,`date`,`dayOfWeek`,`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,$21,$22);' }, original: [Error: SQLITE_CONSTRAINT: UNIQUE constraint failed: playbackSessions.id] { errno: 19, code: 'SQLITE_CONSTRAINT', sql: 'INSERT INTO `playbackSessions` (`id`,`mediaItemId`,`mediaItemType`,`displayTitle`,`displayAuthor`,`duration`,`playMethod`,`mediaPlayer`,`startTime`,`currentTime`,`serverVersion`,`coverPath`,`timeListening`,`mediaMetadata`,`date`,`dayOfWeek`,`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,$21,$22);' }, fields: [ 'id' ], sql: 'INSERT INTO `playbackSessions` (`id`,`mediaItemId`,`mediaItemType`,`displayTitle`,`displayAuthor`,`duration`,`playMethod`,`mediaPlayer`,`startTime`,`currentTime`,`serverVersion`,`coverPath`,`timeListening`,`mediaMetadata`,`date`,`dayOfWeek`,`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,$21,$22);' } ``` Error log part 2: ``` 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:142:7) at async PlaybackSessionManager.syncLocalSessionRequest (/server/managers/PlaybackSessionManager.js:192:20) { name: 'SequelizeUniqueConstraintError', errors: [ ValidationErrorItem { message: 'id must be unique', type: 'unique violation', path: 'id', value: '54396192-ebfd-4107-ab68-7ea351d572ea', origin: 'DB', instance: playbackSession { dataValues: { ``` ### Steps to reproduce the issue 1. Move away from your server (no connection to the server) 2. Listen to an audiobook on your way to work 3. Listen to an audiobook on your way from work 4. return to your home wifi 5. server crashes, becuase all listening sessions of the day will get the same `id` ### Audiobookshelf version v2.5.0 ### How are you running audiobookshelf? Docker
adam added the bug label 2026-04-24 23:48:18 +02:00
adam closed this issue 2026-04-24 23:48:18 +02:00
Author
Owner

@advplyr commented on GitHub (Nov 7, 2023):

You are using the iOS app?

@advplyr commented on GitHub (Nov 7, 2023): You are using the iOS app?
Author
Owner

@Gorasa commented on GitHub (Nov 7, 2023):

Yes iOS app is correct.

@Gorasa commented on GitHub (Nov 7, 2023): Yes iOS app is correct.
Author
Owner

@advplyr commented on GitHub (Nov 18, 2023):

This is fixed in the latest iOS app release https://github.com/advplyr/audiobookshelf-app/releases/tag/v0.9.67-beta

@advplyr commented on GitHub (Nov 18, 2023): This is fixed in the latest iOS app release https://github.com/advplyr/audiobookshelf-app/releases/tag/v0.9.67-beta
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/audiobookshelf#1514