audiobookshelf
audiobookshelf copied to clipboard
[Bug]: Server crashes
Describe the issue
FATAL: [Server] Unhandled rejection: TypeError: Cannot read properties of undefined (reading 'authors'), promise: Promise {
audiobookshelf |
Steps to reproduce the issue
- Matching a book using audible.com
Audiobookshelf version
v2.8.0
How are you running audiobookshelf?
Docker
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
Thanks. In your server settings, Do you have "Store covers with item" enabled?
Yes I do.
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:
- The new cover in the book's library directory triggers the library watcher, which checks if it needs to do something with that file.
- 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.
Hi, thank you for your detailed response and workaround. Also thank you in advance for the fix.
Fixed in v2.8.1
Thank you again for fixing this. Much appreciated.