audiobookshelf icon indicating copy to clipboard operation
audiobookshelf copied to clipboard

[Bug]: Cancelling playback of audiobook before it starts crashes server / causes container to stop

Open Leondre opened this issue 2 years ago • 6 comments

Describe the issue

100% reproducible on my end. Simply stop playback of an audiobook while it is still loading and the container will crash.

spinnyboi

[2022-07-18 19:55:21]  INFO: [PlaybackSessionManager] startSession: Closing open session "Hateful Things" for user "root"
[2022-07-18 19:55:21]  INFO: [STREAM] START STREAM - Num Segments: 2275
[2022-07-18 19:55:21]  INFO: [INFO] FFMPEG transcoding started with command: ffmpeg -seek_timestamp 1 -f concat -safe 0 -i /metadata/streams/play_vhq6y64kf8qvx1nike/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/play_vhq6y64kf8qvx1nike/output-%d.ts /metadata/streams/play_vhq6y64kf8qvx1nike/final-output.m3u8
[2022-07-18 19:55:21]  INFO: 
[2022-07-18 19:55:21]  INFO: [adts @ 0x148eb72be640] Scalable configurations are not allowed in ADTS
[2022-07-18 19:55:21]  INFO: Could not write header for output file #0 (incorrect codec parameters ?): Invalid data found when processing input
[2022-07-18 19:55:21]  INFO: Error initializing output stream 0:0 -- 
[2022-07-18 19:55:21]  INFO: 
[2022-07-18 19:55:21]  INFO: 
[2022-07-18 19:55:21]  INFO: [Stream] Re-attempting stream with AAC encode
[2022-07-18 19:55:21]  INFO: [HlsRouter] Stream play_vhq6y64kf8qvx1nike is currently resetting
[2022-07-18 19:55:22]  INFO: Closing Stream play_vhq6y64kf8qvx1nike
[2022-07-18 19:55:22]  INFO: Deleted session data /metadata/streams/play_vhq6y64kf8qvx1nike
[2022-07-18 19:55:31]  INFO: Stream Reset New Start Time 0:00.0
[2022-07-18 19:55:31]  INFO: [STREAM] START STREAM - Num Segments: 2275

** Press ANY KEY to close this window ** 

Steps to reproduce the issue

  1. Start playing an audiobook
  2. While the play/pause button indicates the file is loading/transcoding, press the x button.
  3. Receive crash.

Audiobookshelf version

v2.1.0

How are you running audiobookshelf?

Docker

Leondre avatar Jul 19 '22 00:07 Leondre

What browser are you using and what is the audio file you are playing that is requiring a transcode?

advplyr avatar Jul 19 '22 01:07 advplyr

I am using firefox (102.0.1) and all of my audio files are in m4b. Converted using openaudible if that helps at all.

Leondre avatar Jul 19 '22 01:07 Leondre

I can't reproduce on firefox 102.0 or chrome 103.0.5060.114. It is a little hard to be sure as I need to be pretty fast. I tried on several diffrent books from Google Play, and openaudible

BCNelson avatar Jul 19 '22 18:07 BCNelson

I'm not sure how the audio player was made to look like that screenshot.

advplyr avatar Jul 19 '22 19:07 advplyr

I can't replicate it using edge, in fact none of the files that transcode when trying to play them on firefox do so with edge. Tried firefox in safe mode, same issue so it doesn't seem to be extension related. Also able to replicate on another machine using firefox. Both with and without using nginx as a reverse proxy.

If I can provide any more logs just let me know where from.

That screenshot was just cropped, this is on said other machine in firefox while waiting for playback to start. Sits there for about 20 seconds and then starts playing.

Screenshot 2022-07-19 142420

Leondre avatar Jul 19 '22 19:07 Leondre

Firefox has some issue with direct playing m4b files. We have discussed this in Discord but m4b file will direct play in any chromium based browser. Edge/chrome/brave

advplyr avatar Jul 19 '22 19:07 advplyr

It seems like I am also getting this crash. Playback from the iOS app, docker version hosted on Unraid. Crashes silently (no entry in the logs) sometimes after opening and hitting play.

ohare93 avatar Oct 25 '22 16:10 ohare93

@advplyr i'm not sure if this is the exact issue here, but I ran into a case where multiple m4bs, direct drm-stripped from audible, were causing a re-encode when other m4bs work fine direct. My issue turned out to be some bit that audible sets on specific books, someone did a write up on it here: https://rentry.co/n4ost

after using that example script with bento4 mp4 tools to fix my entire library, this problem no longer occurs. I believe it may be the issue here due to this line: [2022-07-18 19:55:21] INFO: [adts @ 0x148eb72be640] Scalable configurations are not allowed in ADTS

excerpt from page linked above: Trying to extract the AAC audio to an ADTS file with ffmpeg yields the error “Scalable configurations are not allowed in ADTS”, which would suggest this bit is something to do with Scalable Sampling Rate AAC.

Whether that's actually the issue here or not, you should probably be aware of it. I never had this issue with any software for direct listening, and only noticed it when I had higher than expected cpu usage on the host + a large delay in the stream starting. Running that script is now part of my post-procesing when I get a new Audible book. Also, contrary to the stated frequency on this issue, I've had it with completely normal books not just audio plays and audible shorts or whatever they say it's used on there.

itzexor avatar Oct 30 '22 19:10 itzexor

@itzexor Thanks for that info. There was just someone in discord having issues with direct playing m4b and I believe a re-encode fixed it. Were you using firefox when testing this? I believe chromium browsers do a better job with m4b but I have since tested m4b in firefox and all of mine are able to direct play.

advplyr avatar Oct 30 '22 19:10 advplyr

yes i was use firefox, but i think it may also have occurred with the android client. it has been some weeks since i found that so i can't remember the exact details.

itzexor avatar Oct 30 '22 19:10 itzexor

If you have an audible plus account, I think this one should be available free for testing and it should be pretty small download. This book exhibits the bug: https://www.audible.com/pd/Killer-by-Nature-Audiobook/B076XNN4KF

edit: Here's a list of items in my library which the fix script repairs, mostly audible originals and such as stated in the writeup, but at the bottom of the list is several novels that also have the issue.

  • Paula McLain/A Mind of Her Own
  • Marty Ross/The Darkwater Bride - An Audible Original Dram
  • Stephanie K. Smith/Carnival Row - Tangle in the Dark
  • George Orwell/Animal Farm
  • James Dommek, Jr., Josephine Holtzman, Isaac Kestenbaum/Midnight Son
  • Jeff Hirsch/Sovereign
  • John Scalzi/Murder by Other Means - The Dispatcher, Book 2
  • John Scalzi/Travel by Bullet - The Dispatcher, Book 3
  • Alex Michaelides/The Silent Patient
  • Julie Berry/Wishes and Wellingtons
  • Julie Berry/Crime and Carpetbags
  • Julie Berry/Burglars and Bluestockings
  • Matt Berns/The Boys - Deeper and Deeper
  • Faith Hunter/Junkyard Cats - Shining Smith, Book 1
  • Larry Correia/A Murder of Manatees - The Further Adventures of Tom Stranger, Interdimensional Insurance Agent
  • Jan Smith/Killer by Nature - An Audible Original Drama
  • Darrell Brown/Body of Proof - An Audible Original
  • James S.A. Corey/Leviathan Falls - Expanse, Book 9
  • Neal Stephenson/Termination Shock - A Novel
  • Matt Dinniman/The Dungeon Anarchist's Cookbook - Dungeon Crawler Carl, Book 3
  • Matt Dinniman/The Gate of the Feral Gods - Dungeon Crawler Carl, Book 4
  • Matt Dinniman/Carl's Doomsday Scenario - Dungeon Crawler Carl, Book 2
  • Matt Dinniman/The Butcher's Masquerade - Dungeon Crawler Carl, Book 5
  • Terry Goodkind/Heart of Black Ice - Sister of Darkness: The Nicci Chronicles, Book 4

itzexor avatar Oct 30 '22 19:10 itzexor

Sorry to spam this thread so much, but I also remembered that I did have the same initial issue as here where cancelling the playback would crash the container. I think it only happens when you close the player in the browser during the fallback period, where it's trying to play or whatever but hasn't fallen back to a transcode yet. So you should be able to test that issue if you can find a broken m4b and figure out what is going on there, the underlying cause for the delay/transcode I think is this bit issue tho.

itzexor avatar Oct 30 '22 20:10 itzexor

[2023-02-01 06:50:55] INFO: Deleted session data /metadata/streams/play_s4k2n9ixi583j0ait1
/server/libs/njodb/index.js:103
        throw error;
        ^

[Error: ENOENT: no such file or directory, open '/metadata/streams/play_s4k2n9ixi583j0ait1/files.txt'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/metadata/streams/play_s4k2n9ixi583j0ait1/files.txt'
}
npm notice
npm notice New major version of npm available! 8.19.3 -> 9.3.1
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v9.3.1>
npm notice Run `npm install -g [email protected]` to update!
npm notice

Not sure if this is the same but it looks like it. It's a raise condition. It happened when i started playback and my browser had a issue. Not sure what happened. But at the end the container was stopped/crashed.

Pimmetje avatar Feb 01 '23 06:02 Pimmetje

For the past month, this bug has been completely absent 👍 it seems the recent updates have helped stabilise whatever was causing it. Thanks! 🎉

ohare93 avatar Apr 12 '23 08:04 ohare93

@ohare93 Thanks for that follow up. A lot has changed since this original issue so we can consider it closed until someone reproduces.

advplyr avatar Apr 12 '23 13:04 advplyr