OxygenCobalt / Auxio

A simple, rational music player for android
GNU General Public License v3.0
1.82k stars 120 forks source link

Music loading hangs when duplicate artist/genres tags are found #484

Closed ironveil closed 11 months ago

ironveil commented 12 months ago

Describe the Bug/Crash

Within my /music directory, I have two subfolders - one called "studying" which contains relaxing music, and one called "tunes". Previous to version 3.1.2, I used the music folders feature to include/exclude the folder I want to listen to. However, with 3.1.2, the include functionality works but the exclude one doesn't.

  1. Have two folders of music under /music
  2. Go to settings > music folders, and add one of the folders under "exclude"
  3. This happens: Screenshot_20230622-080413_Auxio
  4. The loading dialog box doesn't go away, and it often never actually loads anything.

Describe the intended behavior

The dialog should disappear & I should be able to access my music.

What android version do you use?

Android 13

What device model do you use?

Pixel 7 (EvolutionX)

Bug report

https://drive.google.com/file/d/1ou0aVO1K-fPHOvbFK6FRZpCVQBnKH_Pz/view?usp=sharing

Duplicates

OxygenCobalt commented 12 months ago

I can't reproduce this on my device. I will need some kind of bug report from the latest CI build so I can obtain debug logging that is not normally available in the release build @ironveil.

OxygenCobalt commented 12 months ago

Actually, is it possible that this occurs whenever you press "Refresh music"? That would allow me to narrow the issue down.

animaldaydream commented 12 months ago

Just a few notes, I had tried the GitHub release on this repo, for version 3.1.2, before it got its F-Droid release.

I could recreate this issue multiple consecutive times. I reset the app many times and did both refreshes and rescans many times. It was painful because they were 14k tracks taking about 40 minutes to load (I tried about 4 to 6 times) and I thought it was my new ROM.

The previous F-Droid version picked up the tracks fine at that point.

So here's what I have now:

I had all my music on my device already, so the MediaStore had already caught up when I installed 3.1.1

Today, to test the 3.1.2 F-Droid version, I set up a new folder with 300 tracks copied over from my main music folder on my phone (which is not named Music to avoid Android picking up the music elsewhere, if that even works).

I also placed a single track in the Music folder, and made an extra folder with a single track as well.

Here's what happened:

Auxio refused to load music outside of the folder I use generally. That makes it impossible to test in any practical way, so I placed a .nomedia file on that folder.

After that, Auxio correctly scanned the 300 track test folder. A severe consequence, however, was that I could not change the folder to either of the other single track folders, even after wiping app data.

The workaround was to delete the test folder. Afterwards I could choose a different folder.

A major problem however is that placing the default music folder (named Music) alone on the inclusion list has no effect. Wiping the app data will still reproduce this last problem. In fact, you can set any other folder on the inclusion list and Auxio will pick up that setting.

At this point, I don't know if it's the MediaStore misbehaving, what it's exact effects are here, and how it's supposed to behave. I want to open an issue but I have no idea what's going on.

I'm now gonna have to check if loading my full 14k track library works, but that'll take a while, and I'll fall asleep due to me currently being up at 3 am. [I'll update here tomorrow.] If it doesn't, that might mean the app is now suddenly unable to handle a large library, I think?

ironveil commented 12 months ago

After trying again & clearing storage for Auxio, the issue no longer occurs. I will attach the bug report to the original issue, just in case it is related to @animaldaydream 's issue. I can close it if you want, or I'll leave it open just in case someone else has the issue - but I no longer have this issue.

OxygenCobalt commented 12 months ago

I can't access the bug report @ironveil, as it's actually shared with anyone. If you tried to share with my github email, that will not work since I do not have a google account under that.

I think I have an idea of what the issue is, the music loading process is highly parallelized, and it seems like if one of the threads encounters an error, it causes a deadlock. Cooperative co-routines strike again... I need to rethink error handling here once again @animaldaydream.

ironveil commented 12 months ago

@OxygenCobalt fixed link, made it so anyone can view it. Also I assume it's the correct thing, since I've never made a bug report before.

That makes sense as an issue, since it only had an issue when loading one set of my files (although it's fixed for me now). Good luck!

OxygenCobalt commented 12 months ago

Care to try this APK @animaldaydream? I tried to make the threading not hang on errors. There still should be an error returned, but this way I can at least identify it.

Auxio_Canary.zip

While you're at it, also try to take a bug report so I can capture the error occurring here.

cebzab commented 11 months ago

I have similar issue on my phone with 3.1.2. It's loading music, when it finishes with loading the bar just stops and nothing happens. Music doesn't load and it's just stuck like that. I have Music folder and inside of it bunch of other artist folders. I downloaded also the Auxio_Canary.zip, installed it and grabbed couple screenshots. With this version the behavior is the same but instead of the popup with the bar gets stuck at the end of loading music it just says "Music Loading Failed".

Screenshot_20230624-161443 Screenshot_20230624-161451

I don't know how to grab a bug report, but if somebody explained me the steps I'd be more than happy to provide it.

3.1.1 still works perfectly fine.

OxygenCobalt commented 11 months ago

Great @cebzab! That means my fix worked. You can take a bug report with this guide so I can help resolve the base issue.

cebzab commented 11 months ago

Bug Report: https://drive.google.com/file/d/1jQTUxUPzBdEkOk7747g1uRxpQ8bz5AxU/view?usp=sharing

Edit: For some reason when I click on my link it redirects me to another github page. I'm doing this for the first time, so I still don't get all the github nuances. If the same happens to you, just copy/paste the link in another tab, that should work fine.

OxygenCobalt commented 11 months ago

Thanks for the report @cebzab. It seems to occur at some point when trying to make sure the song's genres are ordered as they are in the file.

Could you take another bug report, this time with this APK? I'm now logging the exact genre information so I'll be able to figure out what conditions cause this mismatch. I am currently struggling to reproduce a genre tag that can cause this issue.

Auxio_Canary.zip

cebzab commented 11 months ago

Here you go sir: https://drive.google.com/file/d/1TZmzIMKMCl-9wekbOHXkc7Jn_itWHLJc/view?usp=sharing

OxygenCobalt commented 11 months ago

That seems to be a bug report from the old APK @cebzab. I need you to install and run the new APK from here. Click on the "Auxio_Canary.zip" provided.

cebzab commented 11 months ago

That's what I believe I did. This time I uninstalled the app, deleted all old apk files from folders and old zip archives, downloaded new one provided in the link, restarted the phone, unzipped and installed the new apk, ran the app, gave permission and retried couple times when it said "Music Loading Failed", then I made the bug report.

https://drive.google.com/file/d/18qh2GRHbJTnVuh16h5QGUx6Fb7x-iht_/view?usp=sharing

OxygenCobalt commented 11 months ago

Thanks @cebzab, that report worked. The error stems from a multi-value genre tag of Pop, Pop, Rok. However, the song is only grouped into a Pop, Rok genre, leading to a mismatch. This is an edge case I need to handle, evidently. I'll get a fix in soon.

animaldaydream commented 11 months ago

The error stems from a multi-value genre tag of Pop, Pop, Rok.

Actually, I have this same issue and this isn't my case. I don't have genre tags at all. I can send a bug report, but I still have 14k tracks. However, I believe I can tell which track is bringing this up. Hang on there.

Edit: I wasn't correct, that track alone can load fine. But it still doesn't work. I'll take a bug report.

OxygenCobalt commented 11 months ago

The fundamental problem is the following @animaldaydream:

  1. Some song has a duplicate piece of artist and/or genre information.
  2. In 3.1.1, Auxio would iterate through these duplicates and end up grouping the songs twice, which then lead them to appearing twice in the artist/genre and having duplicate parent artists/genres.
  3. In 3.1.2, Auxio switched to using sets instead of lists to store child song information, as it allowed the music loader to be parallelized in a non-deterministic way. This prevented the double-grouping from before since sets cannot contain duplicates.
  4. When Songs tried to reorder their artist and genre information to align with the file, it would find that it had more artists/genres than it was actually grouped to. This ends up crashing the music loading process.
  5. The music loading process did not close a communication channel when this error occurred, causing all other parallel routines to deadlock and result in endless loading.

What I need to do is make it so that all songs and albums remove all duplicate artist and genre information to prevent this double-grouping from occurring, in a way that does not lead to inferior metadata.

animaldaydream commented 11 months ago

I understand. Thank you! I'll stay on 3.1.1 then (and also switch to GitHub releases while I'm there. Just in case)

cebzab commented 11 months ago

Nice, you found the culprit. Good luck finding the solution. If there's anything else I can do let me know.

OxygenCobalt commented 11 months ago

Care to try this APK @cebzab @animaldaydream? Duplicate tags should be handled now.

Auxio_Canary.zip

If you encounter more issues, I will need a new bug report.

cebzab commented 11 months ago

This one loads all my music. Good job.