[Bug]: Server crash when closing playback window before transcoding starts #1540

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

Originally created by @dmasice on GitHub (Nov 20, 2023).

Describe the issue

I'm using Firefox from Linux to play some audiobooks. The server is a raspberry pi 4 with docker using the official image.

If the audiobook I'm trying to play requires transcoding, it can take a bit to start streaming. If I push the play button to start playback and close the playback window via the close player button before streaming starts, the server crashes.

I think it could be related to #2157.

Here's the log:

[2023-11-20 13:18:02] DEBUG: [PlaybackSessionManager] startSessionRequest for device Linux x86_64 / Firefox (PlaybackSessionManager.js:64)
[2023-11-20 13:18:02] DEBUG: [PlaybackSessionManager] "admin" starting direct play session for item "8861a05e-f987-41f6-b8ed-fd70a114d13b" with id f4e3df70-8b10-4f65-a2e1-313c227abae0 (Device: Linux x86_64 / Firefox) (PlaybackSessionManager.js:240)
[2023-11-20 13:18:03] DEBUG: [PlaybackSessionManager] startSessionRequest for device Linux x86_64 / Firefox (PlaybackSessionManager.js:64)
[2023-11-20 13:18:03] INFO: [PlaybackSessionManager] startSession: Closing open session "BOOK_TITLE" for user "admin" (Device: Linux x86_64 / Firefox)
[2023-11-20 13:18:03] DEBUG: [PlaybackSessionManager] closeSession "f4e3df70-8b10-4f65-a2e1-313c227abae0" (PlaybackSessionManager.js:306)
[2023-11-20 13:18:03] DEBUG: [PlaybackSessionManager] Removed session "f4e3df70-8b10-4f65-a2e1-313c227abae0" (PlaybackSessionManager.js:330)
[2023-11-20 13:18:03] DEBUG: [PlaybackSessionManager] "admin" starting stream session for item "8861a05e-f987-41f6-b8ed-fd70a114d13b" (Device: Linux x86_64 / Firefox) (PlaybackSessionManager.js:244)
[2023-11-20 13:18:03] INFO: [STREAM] START STREAM - Num Segments: 12017
[2023-11-20 13:18:04] INFO: [INFO] FFMPEG transcoding started with command: ffmpeg -seek_timestamp 1 -f concat -safe 0 -i /metadata/streams/987485cd-a3fd-44e8-902a-b57c0374c175/files.txt -y -loglevel error -map 0:a -c:a copy -f hls -copyts -avoid_negative_ts make_non_negative -max_delay 5000000 -max_muxing_queue_size 2048 -hls_time 6 -hls_segment_type mpegts -start_number 0 -hls_playlist_type vod -hls_list_size 0 -hls_allow_cache 0 -hls_segment_filename /metadata/streams/987485cd-a3fd-44e8-902a-b57c0374c175/output-%d.ts /metadata/streams/987485cd-a3fd-44e8-902a-b57c0374c175/final-output.m3u8
[2023-11-20 13:18:04] INFO:
[2023-11-20 13:18:05] INFO: [adts @ 0x7f9fc48340] Scalable configurations are not allowed in ADTS
[2023-11-20 13:18:05] INFO: [out#0/hls @ 0x7f9d232e70] Could not write header (incorrect codec parameters ?): Invalid data found when processing input
[2023-11-20 13:18:05] INFO: [aost#0:0/copy @ 0x7f9dac69f0] Error initializing output stream:
[2023-11-20 13:18:05] INFO:
[2023-11-20 13:18:05] INFO:
[2023-11-20 13:18:05] ERROR: Ffmpeg Err "ffmpeg exited with code 1:
" (Stream.js:342)
[2023-11-20 13:18:05] INFO: [Stream] Re-attempting stream with AAC encode
[2023-11-20 13:18:05] WARN: File path does not exist /metadata/streams/987485cd-a3fd-44e8-902a-b57c0374c175/output-0.ts (HlsRouter.js:75)
[2023-11-20 13:18:05] INFO: [HlsRouter] Stream 987485cd-a3fd-44e8-902a-b57c0374c175 is currently resetting
[2023-11-20 13:18:06] WARN: File path does not exist /metadata/streams/987485cd-a3fd-44e8-902a-b57c0374c175/output-0.ts (HlsRouter.js:75)
[2023-11-20 13:18:06] INFO: [HlsRouter] Stream 987485cd-a3fd-44e8-902a-b57c0374c175 is currently resetting
[2023-11-20 13:18:07] INFO: [Watcher] "Books" Ready
[2023-11-20 13:18:08] WARN: File path does not exist /metadata/streams/987485cd-a3fd-44e8-902a-b57c0374c175/output-0.ts (HlsRouter.js:75)
[2023-11-20 13:18:08] INFO: [HlsRouter] Stream 987485cd-a3fd-44e8-902a-b57c0374c175 is currently resetting
[2023-11-20 13:18:10] DEBUG: [PlaybackSessionManager] closeSession "987485cd-a3fd-44e8-902a-b57c0374c175" (PlaybackSessionManager.js:306)
[2023-11-20 13:18:10] INFO: Closing Stream 987485cd-a3fd-44e8-902a-b57c0374c175
[2023-11-20 13:18:10] INFO: Deleted session data /metadata/streams/987485cd-a3fd-44e8-902a-b57c0374c175
[2023-11-20 13:18:10] DEBUG: [PlaybackSessionManager] Stream closed for session "987485cd-a3fd-44e8-902a-b57c0374c175" (Device: Linux x86_64 / Firefox) (PlaybackSessionManager.js:254)
[2023-11-20 13:18:10] DEBUG: [PlaybackSessionManager] Removed session "987485cd-a3fd-44e8-902a-b57c0374c175" (PlaybackSessionManager.js:330)
[2023-11-20 13:18:15] ERROR: [STREAM] Transcode never closed... (Stream.js:407)
[2023-11-20 13:18:15] INFO: Stream Reset New Start Time 0:00.0
[2023-11-20 13:18:15] INFO: [STREAM] START STREAM - Num Segments: 12017
node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[Error: ENOENT: no such file or directory, open '/metadata/streams/987485cd-a3fd-44e8-902a-b57c0374c175/files.txt'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/metadata/streams/987485cd-a3fd-44e8-902a-b57c0374c175/files.txt'
}

At this point, the server has crashed and the container is restarted. If I let the streaming start, it plays fine.

I've been able to reproduce the crash every single time.

Steps to reproduce the issue

  1. Start playing an audiobook that requires transcoding to play in Firefox.
  2. Wait for the ffmpeg exited with code 1 error to appear in the server log.
  3. Close the player via the close player button and before the new transcoding ffmpeg job starts.
  4. Server crashes after a few seconds, if not immediately.

Audiobookshelf version

v2.5.0

How are you running audiobookshelf?

Docker

Originally created by @dmasice on GitHub (Nov 20, 2023). ### Describe the issue I'm using Firefox from Linux to play some audiobooks. The server is a raspberry pi 4 with docker using the official image. If the audiobook I'm trying to play requires transcoding, it can take a bit to start streaming. If I push the play button to start playback and close the playback window via the close player button before streaming starts, the server crashes. I think it could be related to #2157. Here's the log: ``` [2023-11-20 13:18:02] DEBUG: [PlaybackSessionManager] startSessionRequest for device Linux x86_64 / Firefox (PlaybackSessionManager.js:64) [2023-11-20 13:18:02] DEBUG: [PlaybackSessionManager] "admin" starting direct play session for item "8861a05e-f987-41f6-b8ed-fd70a114d13b" with id f4e3df70-8b10-4f65-a2e1-313c227abae0 (Device: Linux x86_64 / Firefox) (PlaybackSessionManager.js:240) [2023-11-20 13:18:03] DEBUG: [PlaybackSessionManager] startSessionRequest for device Linux x86_64 / Firefox (PlaybackSessionManager.js:64) [2023-11-20 13:18:03] INFO: [PlaybackSessionManager] startSession: Closing open session "BOOK_TITLE" for user "admin" (Device: Linux x86_64 / Firefox) [2023-11-20 13:18:03] DEBUG: [PlaybackSessionManager] closeSession "f4e3df70-8b10-4f65-a2e1-313c227abae0" (PlaybackSessionManager.js:306) [2023-11-20 13:18:03] DEBUG: [PlaybackSessionManager] Removed session "f4e3df70-8b10-4f65-a2e1-313c227abae0" (PlaybackSessionManager.js:330) [2023-11-20 13:18:03] DEBUG: [PlaybackSessionManager] "admin" starting stream session for item "8861a05e-f987-41f6-b8ed-fd70a114d13b" (Device: Linux x86_64 / Firefox) (PlaybackSessionManager.js:244) [2023-11-20 13:18:03] INFO: [STREAM] START STREAM - Num Segments: 12017 [2023-11-20 13:18:04] INFO: [INFO] FFMPEG transcoding started with command: ffmpeg -seek_timestamp 1 -f concat -safe 0 -i /metadata/streams/987485cd-a3fd-44e8-902a-b57c0374c175/files.txt -y -loglevel error -map 0:a -c:a copy -f hls -copyts -avoid_negative_ts make_non_negative -max_delay 5000000 -max_muxing_queue_size 2048 -hls_time 6 -hls_segment_type mpegts -start_number 0 -hls_playlist_type vod -hls_list_size 0 -hls_allow_cache 0 -hls_segment_filename /metadata/streams/987485cd-a3fd-44e8-902a-b57c0374c175/output-%d.ts /metadata/streams/987485cd-a3fd-44e8-902a-b57c0374c175/final-output.m3u8 [2023-11-20 13:18:04] INFO: [2023-11-20 13:18:05] INFO: [adts @ 0x7f9fc48340] Scalable configurations are not allowed in ADTS [2023-11-20 13:18:05] INFO: [out#0/hls @ 0x7f9d232e70] Could not write header (incorrect codec parameters ?): Invalid data found when processing input [2023-11-20 13:18:05] INFO: [aost#0:0/copy @ 0x7f9dac69f0] Error initializing output stream: [2023-11-20 13:18:05] INFO: [2023-11-20 13:18:05] INFO: [2023-11-20 13:18:05] ERROR: Ffmpeg Err "ffmpeg exited with code 1: " (Stream.js:342) [2023-11-20 13:18:05] INFO: [Stream] Re-attempting stream with AAC encode [2023-11-20 13:18:05] WARN: File path does not exist /metadata/streams/987485cd-a3fd-44e8-902a-b57c0374c175/output-0.ts (HlsRouter.js:75) [2023-11-20 13:18:05] INFO: [HlsRouter] Stream 987485cd-a3fd-44e8-902a-b57c0374c175 is currently resetting [2023-11-20 13:18:06] WARN: File path does not exist /metadata/streams/987485cd-a3fd-44e8-902a-b57c0374c175/output-0.ts (HlsRouter.js:75) [2023-11-20 13:18:06] INFO: [HlsRouter] Stream 987485cd-a3fd-44e8-902a-b57c0374c175 is currently resetting [2023-11-20 13:18:07] INFO: [Watcher] "Books" Ready [2023-11-20 13:18:08] WARN: File path does not exist /metadata/streams/987485cd-a3fd-44e8-902a-b57c0374c175/output-0.ts (HlsRouter.js:75) [2023-11-20 13:18:08] INFO: [HlsRouter] Stream 987485cd-a3fd-44e8-902a-b57c0374c175 is currently resetting [2023-11-20 13:18:10] DEBUG: [PlaybackSessionManager] closeSession "987485cd-a3fd-44e8-902a-b57c0374c175" (PlaybackSessionManager.js:306) [2023-11-20 13:18:10] INFO: Closing Stream 987485cd-a3fd-44e8-902a-b57c0374c175 [2023-11-20 13:18:10] INFO: Deleted session data /metadata/streams/987485cd-a3fd-44e8-902a-b57c0374c175 [2023-11-20 13:18:10] DEBUG: [PlaybackSessionManager] Stream closed for session "987485cd-a3fd-44e8-902a-b57c0374c175" (Device: Linux x86_64 / Firefox) (PlaybackSessionManager.js:254) [2023-11-20 13:18:10] DEBUG: [PlaybackSessionManager] Removed session "987485cd-a3fd-44e8-902a-b57c0374c175" (PlaybackSessionManager.js:330) [2023-11-20 13:18:15] ERROR: [STREAM] Transcode never closed... (Stream.js:407) [2023-11-20 13:18:15] INFO: Stream Reset New Start Time 0:00.0 [2023-11-20 13:18:15] INFO: [STREAM] START STREAM - Num Segments: 12017 node:internal/process/promises:279 triggerUncaughtException(err, true /* fromPromise */); ^ [Error: ENOENT: no such file or directory, open '/metadata/streams/987485cd-a3fd-44e8-902a-b57c0374c175/files.txt'] { errno: -2, code: 'ENOENT', syscall: 'open', path: '/metadata/streams/987485cd-a3fd-44e8-902a-b57c0374c175/files.txt' } ``` At this point, the server has crashed and the container is restarted. If I let the streaming start, it plays fine. I've been able to reproduce the crash every single time. ### Steps to reproduce the issue 1. Start playing an audiobook that requires transcoding to play in Firefox. 2. Wait for the `ffmpeg exited with code 1` error to appear in the server log. 3. Close the player via the `close player` button and before the new transcoding ffmpeg job starts. 4. Server crashes after a few seconds, if not immediately. ### Audiobookshelf version v2.5.0 ### How are you running audiobookshelf? Docker
adam added the bug label 2026-04-24 23:49:23 +02:00
adam closed this issue 2026-04-24 23:49:24 +02:00
Author
Owner

@thevoltagesource commented on GitHub (Dec 14, 2023):

I ran in to this issue but in a different situation. My audiobook folder is also my Calibre library. Starting with 2.5.0, when Calibre updates its database, the creation and removal of the metadata.db-journal causes the same exception and the container crashes. This issue also exists in 2.6.0 but was not in 2.4.4 or earlier.

It seems like this might be a side effect of the change made to the watcher to solve the issue of it adding files before they were complete (Watcher triggering scan before file is fully copied to folder https://github.com/advplyr/audiobookshelf/issues/1362).

In my situation the journal file is flagged by watcher to be scanned. While Watcher is in the loop checking to see if the file is done being modified, the file is deleted and Watchers call to fileUtils.getFileMtimeMs throws an exception because the file no longer exists.

@thevoltagesource commented on GitHub (Dec 14, 2023): I ran in to this issue but in a different situation. My audiobook folder is also my Calibre library. Starting with 2.5.0, when Calibre updates its database, the creation and removal of the metadata.db-journal causes the same exception and the container crashes. This issue also exists in 2.6.0 but was not in 2.4.4 or earlier. It seems like this might be a side effect of the change made to the watcher to solve the issue of it adding files before they were complete (Watcher triggering scan before file is fully copied to folder https://github.com/advplyr/audiobookshelf/issues/1362). In my situation the journal file is flagged by watcher to be scanned. While Watcher is in the loop checking to see if the file is done being modified, the file is deleted and Watchers call to fileUtils.getFileMtimeMs throws an exception because the file no longer exists.
Author
Owner

@thevoltagesource commented on GitHub (Dec 30, 2023):

@dmasice I think I found a solution to the issue you and I are both having and a PR has been submitted for consideration. But after digging in to the code, there is something that concerns me with your situation. The Watcher is only monitoring the library paths for changes, so for it to see the temp transcoded/stream files in your metadata folder, it would seem to indicate that your metadata folder is a subfolder in one of your libraries.

I think ideally the folder structure should look something like this:

/docker/abs
/docker/abs/library -> /audiobooks
/docker/abs/metadata -> /metadata
/docker/abs/config -> /config
/docker/abs/podcasts -> /podcasts

But maybe yours is more like this:

/docker/abs
/docker/abs/library -> /audiobooks
/docker/abs/library/metadata -> /metadata
/docker/abs/library/config -> /config
/docker/abs/podcasts -> /podcasts

While it would probably work (and if this is how you have it, it obviously is working), I could see this causing issues with Watcher picking up config changes, backups, temp files for transcoding, etc, and causing unnecessary scans and possibly other unexpected errors/events.

@thevoltagesource commented on GitHub (Dec 30, 2023): @dmasice I think I found a solution to the issue you and I are both having and a PR has been submitted for consideration. But after digging in to the code, there is something that concerns me with your situation. The Watcher is only monitoring the library paths for changes, so for it to see the temp transcoded/stream files in your metadata folder, it would seem to indicate that your metadata folder is a subfolder in one of your libraries. I think ideally the folder structure should look something like this: ``` /docker/abs /docker/abs/library -> /audiobooks /docker/abs/metadata -> /metadata /docker/abs/config -> /config /docker/abs/podcasts -> /podcasts ``` But maybe yours is more like this: ``` /docker/abs /docker/abs/library -> /audiobooks /docker/abs/library/metadata -> /metadata /docker/abs/library/config -> /config /docker/abs/podcasts -> /podcasts ``` While it would probably work (and if this is how you have it, it obviously is working), I could see this causing issues with Watcher picking up config changes, backups, temp files for transcoding, etc, and causing unnecessary scans and possibly other unexpected errors/events.
Author
Owner

@advplyr commented on GitHub (Dec 31, 2023):

Fixed in v2.7.1 thanks @thevoltagesource !

@advplyr commented on GitHub (Dec 31, 2023): Fixed in [v2.7.1](https://github.com/advplyr/audiobookshelf/releases/tag/v2.7.1) thanks @thevoltagesource !
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/audiobookshelf#1540