Skip to content

[Bug]: Server crashes when opening a library's Series page during a scan (Cannot set properties of null (setting 'media')) #5643

Open

Description

@Farathim89

What happened?

The server shut down while I opened a library's Series page. It happened while that library was being scanned (new books in series were being added). After that every client shows "Socket failed to connect" until the server is started again.

Crash log (metadata/logs/crash_logs.txt):

[Server] Unhandled rejection: TypeError: Cannot set properties of null (setting 'media')
    at server/utils/queries/seriesFilters.js
    at Array.map (<anonymous>)
    at Object.getFilteredSeries (server/utils/queries/seriesFilters.js)
    at async ApiRouter.getAllSeriesForLibrary (server/controllers/LibraryController.js)

What did you expect to happen?

The Series page loads (perhaps without the book that is still being added), and the server keeps running.

Steps to reproduce the issue

  1. Add a folder with many books that belong to series to a library and start a scan.
  2. While the scan is still adding books, open that library's Series page.
  3. The server exits with the error above.

It seems to be a timing issue: I checked the database right after the crash and every bookSeries row pointed to a book that has a library item. So a book and its series link were saved a moment before the book's library item, and the Series query ran in between.

Cause

In getFilteredSeries (server/utils/queries/seriesFilters.js, v2.37.1, around line 208):

oldSeries.books = s.bookSeries.map((bs) => {
  const libraryItem = bs.book.libraryItem
  delete bs.book.libraryItem
  libraryItem.media = bs.book   // libraryItem is null for a book whose library item doesn't exist (yet)
  ...

Skipping such books would avoid the crash, e.g.:

oldSeries.books = s.bookSeries.filter((bs) => bs.book?.libraryItem).map((bs) => { ... })

Also, the unhandled rejection takes the whole server down, so one bad row on one page makes every user lose access until a manual restart.

Audiobookshelf version

v2.37.1

How are you running audiobookshelf?

Windows Tray App

What OS is your Audiobookshelf server hosted from?

Windows

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

Chrome (server-side crash; seen from an Electron-based desktop client)

Additional Notes

Possibly related: #4993, #4153 (other Series crashes, closed) and #5215 (scan crashes).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions