nova-video-player / aos-AVP

NOVA opeN sOurce Video plAyer: main repository to build them all
Apache License 2.0
3.37k stars 202 forks source link

[Bug]: App hanging/crashing when browsing Episodes by date #605

Open mschumacher69 opened 2 years ago

mschumacher69 commented 2 years ago

Problem description

I use nova with an SMB server that auto re-scans on every app launch. This used to work flawlessly in the past, but not anymore.

Now, whenever I browse Episodes by date, I cannot play anything unless it finishes a scanning cycle without any changes to the database because it crashes if I visit Episodes by date while it's updating the library. For example if I try to play a file while the database is being updated, it circles, even the file info such as the subtitles and media info would be circling. And if I access the network section during this time, I wouldn't see my indexed folders, even though the SMB itself is there and accessible. And if I keep browsing under Episodes by date while it's refreshing the library, the app crashes to a blue screen and restarts.

Any idea what might be causing this?

Steps to reproduce the issue

  1. Start Nova.
  2. Go to Episodes by date while it's scanning and try to play a file or just browse in there or sit on that view without doing anything.
  3. If you manage to play a file before it crashes, it would circle forever or crash into a blue screen and restart and if you just browse in there or just stay in this view and don't do anything, it would crash into a blue screen and restart.
  4. You wouldn't be able to go to Episodes by date without a crash unless you wait for it to finish scanning and then go to Episodes by date. The successful visit would always have to be after a blank scan that doesn't add/remove anything from the library. So for example, if it scans and adds/removes something from the library, browsing Episodes by date after the scan would crash Nova. Only the next visit after a scan would be successful as long as the last scan didn't add/remove anything from the library.

Expected behavior

You should be able to browse Episodes by date and play files without the app crashing.

Your phone/tablet/androidTV model

Sony Bravia Android TV and Chromecast with Google TV

Operating system version

Android 9 / Android 12

Application version and app store

Latest Version from the Play Store and latest version from GitHub

Additional system information

No response

Debug logs

Not sure how to capture logs on Android TV.

mschumacher69 commented 1 year ago

@courville it did happen today on 6.0.80 github version. Did you get the crash traces?

courville commented 1 year ago

Yes I think I have it (Android 12, Chromecast) in EpisodesByDateActivity:

java.util.concurrent.RejectedExecutionException: Task androidx.loader.content.ModernAsyncTask$3@c385feb rejected from java.util.concurrent.ThreadPoolExecutor@bfca148[Running, pool size = 1, active threads = 1, queued tasks = 5200, completed tasks = 108]
    at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2086)
    at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:848)
    at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1394)
    at androidx.loader.content.ModernAsyncTask.executeOnExecutor(ModernAsyncTask.java:452)
    at androidx.loader.content.AsyncTaskLoader.executePendingTask(AsyncTaskLoader.java:228)
    at androidx.loader.content.AsyncTaskLoader.dispatchOnCancelled(AsyncTaskLoader.java:241)
    at androidx.loader.content.AsyncTaskLoader$LoadTask.onCancelled(AsyncTaskLoader.java:94)
    at androidx.loader.content.ModernAsyncTask.finish(ModernAsyncTask.java:488)
    at androidx.loader.content.ModernAsyncTask$InternalHandler.handleMessage(ModernAsyncTask.java:507)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7839)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

For internal reference only: https://sentry.io/organizations/nova-video-player/issues/3721379768/?project=6363443&referrer=release-issue-stream#exception

courville commented 1 year ago

I know what it is but it does not mean that it will be simple to solve. Related to https://github.com/nova-video-player/aos-AVP/issues/141

courville commented 1 year ago

OK it seems that a LinkedBlockingQueue of capacity 5200 is not enough for you... Let's try to double it and see if it works for you. @mschumacher69 please check this build and let me know if it helps: https://drive.google.com/file/d/1Bk5X_yNrFEAcGfeL51aL1rFBfa4bza8p/view?usp=sharing

mschumacher69 commented 1 year ago

Great thanks, I will test it out when I get back home and let you know how it goes.

mschumacher69 commented 1 year ago

@courville unfortunately it's still crashing when browsing episodes by date while it's still re-scanning.

courville commented 1 year ago

@mschumacher69, I can see the crash. Now that I have your Id it is easier to spot. Question: does it happen only while it is still scanning? When there is no scanning are you still able to reproduce the crash?

mschumacher69 commented 1 year ago

@courville ok I just tested thoroughly and it only crashes if I browse episodes by date while it's scanning. If I wait for the scanning to complete and then browse episodes by date, it doesn't crash.

But while testing, I noticed that some TV series have the wrong info, so I changed info for all episodes under list episodes, but when I go from list episodes back to episodes by date, it crashes. I can replicate this every time I change episode info.

So I was able to identify 2 scenarios where episodes by date crashes:

  1. When browsing episodes by date while it's scanning.
  2. When browsing episodes by date after changing episode info.

So it seems that episodes by date crashes every time you browse it while it's updating (either while scanning or after changing episode info).

courville commented 1 year ago

OK clear thanks, I will try to reproduce on my end.

Pentaphon commented 1 year ago

I just tested thoroughly and it only crashes if I browse episodes by date while it's scanning.

I've actually seen this as well on my Onn 4K with 2GB of RAM. I browsed while it scanned and it crashed so I redid the scan without touching the player and it finished just fine.

courville commented 1 year ago

OK I have some suggestions to test. Let's not put any limit in the LinkedBlockingQueue for now. If this works, second step will be to implement 2 VideoLoaders, one for sequential non schizophrenic episode/movie by date display and another one for the other requests (might speed things up too). Can you please test this build and report if you still have a crash (it might be the case): https://drive.google.com/file/d/1FnlbtnR8VOBKzlxX5kctOXRoXt48sHMD/view?usp=sharing

mschumacher69 commented 1 year ago

Ok so I tested and it didn't crash when I tried browsing episodes by date while it's scanning, but it got stuck when I backed from episodes by date and I had to press the home button on my remote to exit. This only happened the 1st time I tested. Subsequent tries went fine, it doesn't crash while browsing episodes by date while scanning and I can back out of it.

One thing I noticed though is that the rounding circle in the top right disappears after a few seconds even though it still shows as re-scanning under Network and it doesn't seem to be finishing. I tried exiting the app and re-entering several times but it still seems to be stuck on re-scanning under Network but it doesn't show the rounding circle in the top right, so I'm not sure if it's actually scanning or not.

Anyway, I will keep monitoring over the next few days and report back.

Thanks for all your hard work.

courville commented 1 year ago

@mschumacher69 thanks for the testing and report. This gives a valid direction for a fix. I noticed the circle stopping and starting too (I need to see what it means: perhaps internal storage scan, then network storage scan). I have other ideas to test as well. Perhaps this will result in another build to test.

mschumacher69 commented 1 year ago

@courville ok so here's what's happening. I watched an episode and after I finished, it was still stuck on scanning under Network without showing the rounding circle in the top right. I tried exiting and re-entering the app several times but it was still stuck on scanning under Network but it wasn't actually scanning because it didn't add the newly downloaded episodes (this might be a one time fluke, I'll monitor if it happens again).

So I force stopped it and re-entered the app, this time it started scanning properly and showing the rounding circle in the top right. I browsed episodes by date while it's rounding and all was fine, until it detected the new episodes, this is when it froze and I had to exit it with the home button.

So now the difference is that in this test build, it doesn't crash when browsing episodes by date while scanning unless it finds new episodes. Actually it now freezes instead of crashing and restarting, but as I said, only if it finds new episodes after it finishes scanning when under episodes by date, whereas before, it used to crash and restart (not freeze) when browsing episodes by date while it's scanning even if there's no new episodes to add.

So it is an improvement, but not 100% resolved yet.

courville commented 1 year ago

OK trading an issue with another one... Will try to reproduce.

courville commented 1 year ago

Let's try this one with 5s throttling on VideoSelectionLoader and a threadpool of size 1: https://drive.google.com/file/d/17TDo4Cbb7dFoAX4kljjhSVYSKPrgK6Bu/view?usp=sharing Not sure it will help. It could be interesting to wait for the app to crash following the freeze (or ANR) to get a better feel of what is stuck of you can. P.S.: instead of providing universal builds, I could provide arm32 ones to be more inline of version numbering of your device abi compatible with google play one.

courville commented 1 year ago

FTR, now there is an "infinite" loader pool that are updated all at once when a new episode is detected which could be overwhelming for the device and cause the freeze. Perhaps this is the interpretation of what happens. If this is the case, I do not see any viable solution (other than blocking such heavy views while scanning).

mschumacher69 commented 1 year ago

Ok I'll give it a try, but I have to wait until I have new episodes available. I'll also wait for the app to crash or ANR once it freezes.

Yeah you can provide arm32 builds instead of universal ones.

courville commented 1 year ago

BTW current fixes have been released on github as 6.0.83 pre-release with an arm32 build.

mschumacher69 commented 1 year ago

Ok I'll test on 6.0.83 and report back, but still waiting for new episodes to be available.

I'll let you know.

mschumacher69 commented 1 year ago

@courville ok so I got new episodes, I browsed episodes by date while it was scanning, all was fine until it detected the new episodes and froze. I waited for it as you suggested, it crashed and restarted. I tried browsing episodes by date while scanning after it restarted and it was freezing and crashing every time even though it wasn't adding new episodes. This happened around 3 times and after that it was stuck on scanning under Network without showing the rounding icon in the top right like what happened last time. So I force stopped it and tried again, it froze and crashed once while scanning in episodes by date and now it doesn't crash anymore while scanning in episodes by date.

I have a suggestion for a workaround if you don't have a fix, maybe if you set it to not refresh the episodes by date view when inside this view after scanning and only refresh it in the background when outside the episodes by date view?

courville commented 1 year ago

Thx for the feedback and testing. I guess I could LoaderManager.getInstance(this).destroyLoader(cursorLoader.getId()); when in the EpisodesByDate activity. This could prevent the freeze and crash. Will experiment on it.

courville commented 1 year ago

Strangely enough, there is no recorded crash for Chromecast device on sentry backend these last days...

mschumacher69 commented 1 year ago

That's strange, it crashed at least 4-5 times when I was testing yesterday.

I'm on the latest 6.0.83 from github.

courville commented 1 year ago

Anyway the solution is for complex views (EpisodesByDate, MoviesByGenre) is to use cursor loaders that do not update so that the overall system does not explode while scanning network shares. Downside If there is new video file, users might have to exit and re-enter the activity for a refresh.

mschumacher69 commented 1 year ago

Yeah I think that would be an acceptable trade off as long as we don't have to exit and re-enter the whole app for a refresh.

courville commented 1 year ago

OK let's experiment to stopLoader when result is available with onLoadFinished cf. https://stackoverflow.com/questions/21149917/is-it-actually-unsafe-to-call-stoploading-on-a-loader-that-is-being-managed even if this is not recommended in https://developer.android.com/reference/androidx/loader/content/Loader.html#stopLoading() This should stop the Loader to update in case of newer videos. @mschumacher69 could you please try this build: https://drive.google.com/file/d/1qIzVO6ihrR6Keo6hwVohB4hJe_GyFR1j/view?usp=sharing and let me know if it helps? It will not impact the other views than the thematic ones (e.g. EpisodesByDate, MoviesByGenre etc.).

mschumacher69 commented 1 year ago

Sure, I'll let you know once I have new episodes.

mschumacher69 commented 1 year ago

@courville does this last change only apply to new videos or does it also apply to removing videos?

Because today I deleted episodes from the share and it crashed once in episodes by date after the deletion, do you see it in the sentry backend?

I'm still waiting for new episodes to test with new videos.

courville commented 1 year ago

The last change only says to make a query on the db to display the current view only once and do not refresh it if there is changes while on the current view. Thus it should not be the cause of your crash. Perhaps your crash is this one https://sentry.io/organizations/nova-video-player/issues/3753224570/?project=6363443&query=release%3Aorg.courville.nova%406.0.84-20221119.1915%2B2547701+error.unhandled%3Atrue&referrer=issue-stream&sort=freq

java.lang.ArrayIndexOutOfBoundsException: null
    at androidx.leanback.widget.CursorObjectAdapter.get(CursorObjectAdapter.java:143)
    at androidx.leanback.widget.ItemBridgeAdapter.getItemViewType(ItemBridgeAdapter.java:296)
    at androidx.recyclerview.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:6160)
    at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6339)
    at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6300)
    at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6296)
    at androidx.leanback.widget.GridLayoutManager.getViewForPosition(GridLayoutManager.java:1143)
    at androidx.leanback.widget.GridLayoutManager$2.createItem(GridLayoutManager.java:1672)
    at androidx.leanback.widget.SingleRow.appendVisibleItems(SingleRow.java:115)
    at androidx.leanback.widget.Grid.appendVisibleItems(Grid.java:408)
    at androidx.leanback.widget.GridLayoutManager.appendVisibleItems(GridLayoutManager.java:1992)
    at androidx.leanback.widget.GridLayoutManager.scrollDirectionPrimary(GridLayoutManager.java:2515)
    at androidx.leanback.widget.GridLayoutManager.scrollHorizontallyBy(GridLayoutManager.java:2444)
    at androidx.recyclerview.widget.RecyclerView.scrollStep(RecyclerView.java:1969)
    at androidx.recyclerview.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:5476)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1037)
    at android.view.Choreographer.doCallbacks(Choreographer.java:845)
    at android.view.Choreographer.doFrame(Choreographer.java:775)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1022)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7839)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

Breadcrumbs say:

ui.lifecycle
{
screen: EpisodesByDateActivity, 
state: started
}
Info
17:46:54
ui.lifecycle
{
screen: VideoDetailsActivity, 
state: paused
}
Info
17:46:55
ui.lifecycle
{
screen: EpisodesByDateActivity, 
state: resumed
}
Info
17:46:55
ui.lifecycle
{
screen: VideoDetailsActivity, 
state: stopped
}
Info
17:46:55

Perhaps I am mixing cursors somehow transitioning from one View to another one (EpisodesByDateActivity->VideoDetailsActivity->EpisodesByDateActivity)... Would you have a way to reproduce?

courville commented 1 year ago

Ok, I am able to reproduce and I will fix the issue.

mschumacher69 commented 1 year ago

Ok great. So shall I update to 6.0.86 or do you still need me to test anything on this current test build?

courville commented 1 year ago

Please wait for the 6.0.87 release later tonight.

mschumacher69 commented 1 year ago

Ok I'll wait for 6.0.87.

But something odd happened today, I deleted episodes from the share and browsed episodes by date while it's scanning to see if it's gonna freeze/crash, it didn't and the episodes didn't disappear from episodes by date (which I know is working as intended), so I exited episodes by date and re-entered to see if it's going to update and if it's going to freeze/crash, it updated and the episodes disappeared and it didn't freeze/crash.

But what happened after that is that every time I play a file, video stutters heavily and plays extremely slowly and would be out of sync with audio. I tried exiting and re-entering the app, the same issue persisted. I tried force stopping the app several times, but the app blue screened and couldn't start anymore. I had to reboot the Chromecast for the issue to clear.

This issue used to happen sometimes when the app used to crash in episodes by date.

Anyway, hopefully if the whole crashing issue is fixed in 6.0.87, I'm hoping that this other issue won't happen anymore.

mschumacher69 commented 1 year ago

Ok thanks, I'll give it a go and let you know.

courville commented 1 year ago

For your video stuttering issue, it might be that the multimedia stack of the chromecast was fubar. Will need some logs if it happens again.

mschumacher69 commented 1 year ago

For your video stuttering issue, it might be that the multimedia stack of the chromecast was fubar. Will need some logs if it happens again.

Ok I will let you know if the stuttering issue happens again.

But the freezing/crashing issue is still happening on 6.0.87. I browsed episodes by date while it's scanning right after I installed it (no new files or deleted files), but it froze after a while and restarted, tried episodes by date again, froze and restarted again, I then waited for it to complete the scan (waited for the rounding icon in the top right to disappear) before I go into episodes by date, it didn't crash, but I noticed that even though the rounding icon disappeared in the top right, it was still showing as scanning under Network. So I force stopped it and tried again, the same thing happened again, froze and restarted while browsing episodes by date while it's scanning, then I browsed episodes by date after the rounding icon in the top right disappeared, it didn't crash but it was also still showing as scanning under Network without showing the rounding icon in the top right and it seems to stay stuck in this state where the green rescan icon keeps rounding under Network without showing a rounding icon in the top right until I force stop the app.

The only way to get it to complete the scan is to wait for the scan to complete before browsing episodes by date.

courville commented 1 year ago

OK thus throttling with 1 hour delay does not help. The only way is to stop loaders according to your feedback on 6.0.85 leading to the crash when entering videoIDetailsFragment and getting back to episodesByDate fragment. I thus need to understand how to not confuse loaders/cursors. Thanks for the testing and feedback.

mschumacher69 commented 1 year ago

@courville anything I should lookout for in 6.0.88 or did you not attempt to change anything regarding this issue in this version?

courville commented 1 year ago

@mschumacher69 not yet sorry (working on it still).

mschumacher69 commented 1 year ago

Ok thanks, let me know when you need me to test a new build.

mschumacher69 commented 1 year ago

@courville any progress on this?

mschumacher69 commented 1 year ago

@courville any chance of fixing this? Still happening on the latest github release.

courville commented 1 year ago

@mschumacher69 unfortunately, not working on it since I exhausted all the ideas I had for a possible fix. Will get back on the topic but it might require migration to livedata which is another scale of magnitude of refactoring.

mschumacher69 commented 1 year ago

@courville ok thanks, just let me know if you need me to test anything.

mschumacher69 commented 7 months ago

@courville any progress on this?

courville commented 7 months ago

unfortunately not for now

Pentaphon commented 7 months ago

@mschumacher69 i've noticed better stability on Nova thanks to courville's past year of bugfixes resulting from the sentry logs Nova has been cataloguing. What's your experience with the most recent builds on your TV?

mschumacher69 commented 7 months ago

It still crashes whenever I visit episodes by date while it's scanning or if there was content added/removed from the last time I visited it.

Pentaphon commented 7 months ago

It still crashes whenever I visit episodes by date while it's scanning or if there was content added/removed from the last time I visited it.

Ok now I have some questions that will hopefully help courville fix this issue for you:

  1. Are you getting crashes on the latest github release as of today? (v6.2.54)
  2. What device is the SMB share on? PC with Windows? Ubuntu server? Mac? Synology NAS?
  3. Have you tried using SMBJ as opposed to regular SMB on Nova? SMBJ support was detailed here: https://github.com/nova-video-player/aos-AVP/issues/835 and you can figure out how to connect using SMBJ there. Do you get crashes on BOTH SMB and SMBJ connections?