[Bug]: Server crashes #1783

Closed
opened 2026-04-24 23:58:11 +02:00 by adam · 8 comments
Owner

Originally created by @digitalwm on GitHub (Mar 1, 2024).

Describe the issue

FATAL: [Server] Unhandled rejection: TypeError: Cannot read properties of undefined (reading 'authors'), promise: Promise {
audiobookshelf | TypeError: Cannot read properties of undefined (reading 'authors')
audiobookshelf | at BookScanner.scanNewBookLibraryItem (/server/scanner/BookScanner.js:446:86)
audiobookshelf | at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
audiobookshelf | at async LibraryItemScanner.scanNewLibraryItem (/server/scanner/LibraryItemScanner.js:178:24)
audiobookshelf | at async LibraryScanner.scanFolderUpdates (/server/scanner/LibraryScanner.js:584:30)
audiobookshelf | at async LibraryScanner.scanFilesChanged (/server/scanner/LibraryScanner.js:385:33)
audiobookshelf | } (Server.js:166)

Steps to reproduce the issue

  1. Matching a book using audible.com

Audiobookshelf version

v2.8.0

How are you running audiobookshelf?

Docker

Originally created by @digitalwm on GitHub (Mar 1, 2024). ### Describe the issue FATAL: [Server] Unhandled rejection: TypeError: Cannot read properties of undefined (reading 'authors'), promise: Promise { audiobookshelf | <rejected> TypeError: Cannot read properties of undefined (reading 'authors') audiobookshelf | at BookScanner.scanNewBookLibraryItem (/server/scanner/BookScanner.js:446:86) audiobookshelf | at process.processTicksAndRejections (node:internal/process/task_queues:95:5) audiobookshelf | at async LibraryItemScanner.scanNewLibraryItem (/server/scanner/LibraryItemScanner.js:178:24) audiobookshelf | at async LibraryScanner.scanFolderUpdates (/server/scanner/LibraryScanner.js:584:30) audiobookshelf | at async LibraryScanner.scanFilesChanged (/server/scanner/LibraryScanner.js:385:33) audiobookshelf | } (Server.js:166) ### Steps to reproduce the issue 1. Matching a book using audible.com ### Audiobookshelf version v2.8.0 ### How are you running audiobookshelf? Docker
adam added the bug label 2026-04-24 23:58:11 +02:00
adam closed this issue 2026-04-24 23:58:11 +02:00
Author
Owner

@mikiher commented on GitHub (Mar 1, 2024):

Looking at the stack trace, the crash seems to have happened not while matching, but while the library watcher was adding a new book (but perhaps both things happened around the same time). The error itself is also very odd.

Can you please attach the full log file so I can examine what led up to the crash? you can find it under <your_metadata_dir>/logs/daily

@mikiher commented on GitHub (Mar 1, 2024): Looking at the stack trace, the crash seems to have happened not while matching, but while the library watcher was adding a new book (but perhaps both things happened around the same time). The error itself is also very odd. Can you please attach the full log file so I can examine what led up to the crash? you can find it under <your_metadata_dir>/logs/daily
Author
Owner

@digitalwm commented on GitHub (Mar 3, 2024):

2024-03-01.txt

@digitalwm commented on GitHub (Mar 3, 2024): [2024-03-01.txt](https://github.com/advplyr/audiobookshelf/files/14473550/2024-03-01.txt)
Author
Owner

@mikiher commented on GitHub (Mar 8, 2024):

Thanks. In your server settings, Do you have "Store covers with item" enabled?

@mikiher commented on GitHub (Mar 8, 2024): Thanks. In your server settings, Do you have "Store covers with item" enabled?
Author
Owner

@digitalwm commented on GitHub (Mar 8, 2024):

Yes I do.

@digitalwm commented on GitHub (Mar 8, 2024): Yes I do.
Author
Owner

@mikiher commented on GitHub (Mar 8, 2024):

OK, then I believe I understand the root cause for this crash.

TLDR: This is caused by a race condition accessing Database.libraryFilterData[libraryId]. This race condition happens because the Store covers with item setting is enabled.

Analysis:
Store covers with item enabled means that when submitting a match result with a new cover, the cover is downloaded to the book's library directory, rather than then to the book's metadata directory. Now two things happen in parallel:

  1. The new cover in the book's library directory triggers the library watcher, which checks if it needs to do something with that file.
  2. Book metadata changes due to the submitted match are updated in the book's record.

The two code paths above might be running interleaved due to their asynchronous nature.

Specifically, within path 1, the following happens:
1.a. Database.libraryFilterData[libraryId] is populated here
1.b Database.libraryFilterData[libraryId] is accessed here (where the crash happens).

and within code path 2, the following happens:
2.a. Database.libraryFilterData[libraryId] is deleted (since it's invalid and needs to be reread) here

Now, since the code between 1.a and 1.b is highly asynchronous, the code may run in the following sequence:

  • 1.a
  • 2.a
  • 1.b

This will cause the crash we see at 1.b, since Database.libraryFilterData[libraryId] is deleted at that point.

Solution:
Database.libraryFilterData[libraryId] needs to be checked for validity right before every access.

I will work on a fix.

As a workaround until this is fixed, you can disable the Store covers with item setting, or disable the library watcher.

@mikiher commented on GitHub (Mar 8, 2024): OK, then I believe I understand the root cause for this crash. TLDR: This is caused by a race condition accessing `Database.libraryFilterData[libraryId]`. This race condition happens because the `Store covers with item` setting is enabled. Analysis: `Store covers with item` enabled means that when submitting a match result with a new cover, the cover is downloaded to the book's library directory, rather than then to the book's metadata directory. Now two things happen in parallel: 1. The new cover in the book's library directory triggers the library watcher, which checks if it needs to do something with that file. 2. Book metadata changes due to the submitted match are updated in the book's record. The two code paths above might be running interleaved due to their asynchronous nature. Specifically, within path 1, the following happens: 1.a. Database.libraryFilterData[libraryId] is populated [here](https://github.com/advplyr/audiobookshelf/blob/153f149d582d378e5185240ae672d01d10b33e03/server/scanner/LibraryScanner.js#L458) 1.b Database.libraryFilterData[libraryId] is accessed [here](https://github.com/advplyr/audiobookshelf/blob/153f149d582d378e5185240ae672d01d10b33e03/server/scanner/BookScanner.js#L446) (where the crash happens). and within code path 2, the following happens: 2.a. Database.libraryFilterData[libraryId] is deleted (since it's invalid and needs to be reread) [here](https://github.com/advplyr/audiobookshelf/blob/153f149d582d378e5185240ae672d01d10b33e03/server/Database.js#L434) Now, since the code between 1.a and 1.b is highly asynchronous, the code may run in the following sequence: - 1.a - 2.a - 1.b This will cause the crash we see at 1.b, since Database.libraryFilterData[libraryId] is deleted at that point. Solution: Database.libraryFilterData[libraryId] needs to be checked for validity right before every access. I will work on a fix. As a workaround until this is fixed, you can disable the `Store covers with item` setting, or disable the library watcher.
Author
Owner

@digitalwm commented on GitHub (Mar 8, 2024):

Hi, thank you for your detailed response and workaround.
Also thank you in advance for the fix.

@digitalwm commented on GitHub (Mar 8, 2024): Hi, thank you for your detailed response and workaround. Also thank you in advance for the fix.
Author
Owner

@advplyr commented on GitHub (Mar 17, 2024):

Fixed in v2.8.1

@advplyr commented on GitHub (Mar 17, 2024): Fixed in [v2.8.1](https://github.com/advplyr/audiobookshelf/releases/tag/v2.8.1)
Author
Owner

@digitalwm commented on GitHub (Mar 18, 2024):

Thank you again for fixing this. Much appreciated.

@digitalwm commented on GitHub (Mar 18, 2024): Thank you again for fixing this. Much appreciated.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/audiobookshelf#1783