Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Large queues cause extreme lag/out-of-memory crashes #842

Closed
Wjxfi opened this issue Jul 27, 2024 · 51 comments
Closed

Large queues cause extreme lag/out-of-memory crashes #842

Wjxfi opened this issue Jul 27, 2024 · 51 comments
Assignees
Labels
bug Something isn't working critical Need to get this fixed right now ui Related to app UI

Comments

@Wjxfi
Copy link

Wjxfi commented Jul 27, 2024

remove the lags please, it's impossible to use, okie ? optimize

@Wjxfi
Copy link
Author

Wjxfi commented Jul 27, 2024

Sorry

@OxygenCobalt
Copy link
Owner

Where does it specifically lag @Wjxfi?

@Wjxfi
Copy link
Author

Wjxfi commented Jul 27, 2024

everywhere, when I turn on music it lags and just interrupts constantly sometimes the application crashes altogether @OxygenCobalt

@OxygenCobalt
Copy link
Owner

Screen recording @Wjxfi?

@Wjxfi
Copy link
Author

Wjxfi commented Jul 27, 2024

Ok soon

@Wjxfi
Copy link
Author

Wjxfi commented Jul 27, 2024

@Wjxfi
Copy link
Author

Wjxfi commented Jul 27, 2024

it only starts if you wait a long time and only then click on the song, otherwise it crashes

@Wjxfi
Copy link
Author

Wjxfi commented Jul 27, 2024

@OxygenCobalt for u :3

@OxygenCobalt
Copy link
Owner

OxygenCobalt commented Jul 27, 2024

Is there an older version that doesnt do this @Wjxfi?

@Wjxfi
Copy link
Author

Wjxfi commented Jul 27, 2024

Is there an older version that doesnt do this @Wjxfi?

Well, it didn't lag before, but I don't remember which version. Maybe it's because I added more songs.

@OxygenCobalt
Copy link
Owner

OxygenCobalt commented Jul 27, 2024

Can you try old versions @Wjxfi? Find the latest one that worked.

@Wjxfi
Copy link
Author

Wjxfi commented Jul 27, 2024

Can you try old versions @Wjxfi? Find the latest one that worked.

Sorry, I can't roll back without losing playlist data and more. long correction: there are more than two dozen of them. I'm 90% sure that everything worked 95% better than in this version - in version 3.5.0. more likely. on 3.4.3 I think everything worked for sure. @OxygenCobalt

@OxygenCobalt
Copy link
Owner

Can you try old versions @Wjxfi? Find the latest one that worked.

Sorry, I can't roll back without losing playlist data and more. long correction: there are more than two dozen of them. I'm 90% sure that everything worked 95% better than in this version - in version 3.5.0. more likely. on 3.4.3 I think everything worked for sure. @OxygenCobalt

Can you not export all of your playlists and try 3.4.3 just in case?

@Wjxfi
Copy link
Author

Wjxfi commented Jul 27, 2024

Most likely it's a matter of the latest update. in f-droid after 3.5.0 comes 3.5.2

@OxygenCobalt
Copy link
Owner

Most likely it's a matter of the latest update. in f-droid after 3.5.0 comes 3.5.2

I cannot resolve your issue without a good idea of the changes that broke it. Please test older versions, just export your playlists.

@Wjxfi
Copy link
Author

Wjxfi commented Jul 27, 2024

i have more than 45 playlists but i still decided to do it. and lol when i try to export at least one with both methods my app crashes

@Wjxfi
Copy link
Author

Wjxfi commented Jul 27, 2024

I'm sure it's because of the last update and its changes. I could export normally before. @OxygenCobalt

@OxygenCobalt
Copy link
Owner

I'm sure it's because of the last update and its changes. I could export normally before. @OxygenCobalt

Can you take a bug report when these crashes happen @Wjxfi

@Wjxfi
Copy link
Author

Wjxfi commented Jul 27, 2024

I'm sure it's because of the last update and its changes. I could export normally before. @OxygenCobalt

Can you take a bug report when these crashes happen @Wjxfi

ok I'll try to do that

@Wjxfi
Copy link
Author

Wjxfi commented Jul 27, 2024

I'm sure it's because of the last update and its changes. I could export normally before. @OxygenCobalt

FATAL EXCEPTION: DefaultDispatcher-worker-3
Process: org.oxycblt.auxio, PID: 1130
java.lang.IllegalArgumentException: Unknown URI: content://downloads/public_downloads/6499
	at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:172)
	at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
	at android.content.ContentProviderProxy.query(ContentProviderNative.java:481)
	at android.content.ContentResolver.query(ContentResolver.java:1219)
	at android.content.ContentResolver.query(ContentResolver.java:1151)
	at android.content.ContentResolver.query(ContentResolver.java:1107)
	at org.oxycblt.auxio.music.fs.StorageUtilKt.safeQuery(Unknown Source:11)
	at org.oxycblt.auxio.music.fs.DocumentPathFactoryImpl.unpackDocumentUri(Unknown Source:52)
	at org.oxycblt.auxio.music.MusicViewModel$exportPlaylist$1.invokeSuspend(SourceFile:42)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(Unknown Source:8)
	at kotlinx.coroutines.DispatchedTask.run(Unknown Source:94)
	at androidx.core.app.ActivityRecreator$1.run(SourceFile:40)
	at kotlinx.coroutines.scheduling.TaskImpl.run(Unknown Source:2)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(SourceFile:92)
	Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@aaad05a, Dispatchers.IO]

export crash log

@OxygenCobalt
Copy link
Owner

I'm sure it's because of the last update and its changes. I could export normally before. @OxygenCobalt

FATAL EXCEPTION: DefaultDispatcher-worker-3
Process: org.oxycblt.auxio, PID: 1130
java.lang.IllegalArgumentException: Unknown URI: content://downloads/public_downloads/6499
	at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:172)
	at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
	at android.content.ContentProviderProxy.query(ContentProviderNative.java:481)
	at android.content.ContentResolver.query(ContentResolver.java:1219)
	at android.content.ContentResolver.query(ContentResolver.java:1151)
	at android.content.ContentResolver.query(ContentResolver.java:1107)
	at org.oxycblt.auxio.music.fs.StorageUtilKt.safeQuery(Unknown Source:11)
	at org.oxycblt.auxio.music.fs.DocumentPathFactoryImpl.unpackDocumentUri(Unknown Source:52)
	at org.oxycblt.auxio.music.MusicViewModel$exportPlaylist$1.invokeSuspend(SourceFile:42)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(Unknown Source:8)
	at kotlinx.coroutines.DispatchedTask.run(Unknown Source:94)
	at androidx.core.app.ActivityRecreator$1.run(SourceFile:40)
	at kotlinx.coroutines.scheduling.TaskImpl.run(Unknown Source:2)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(SourceFile:92)
	Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@aaad05a, Dispatchers.IO]

export crash log

You cannot export to the downloads folder, Auxio cannot handle those paths. Try another folder @Wjxfi

@Wjxfi

This comment was marked as off-topic.

@Wjxfi

This comment was marked as off-topic.

@Wjxfi
Copy link
Author

Wjxfi commented Jul 27, 2024

I'm sure it's because of the last update and its changes. I could export normally before. @OxygenCobalt

FATAL EXCEPTION: DefaultDispatcher-worker-3
Process: org.oxycblt.auxio, PID: 1130
java.lang.IllegalArgumentException: Unknown URI: content://downloads/public_downloads/6499
	at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:172)
	at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
	at android.content.ContentProviderProxy.query(ContentProviderNative.java:481)
	at android.content.ContentResolver.query(ContentResolver.java:1219)
	at android.content.ContentResolver.query(ContentResolver.java:1151)
	at android.content.ContentResolver.query(ContentResolver.java:1107)
	at org.oxycblt.auxio.music.fs.StorageUtilKt.safeQuery(Unknown Source:11)
	at org.oxycblt.auxio.music.fs.DocumentPathFactoryImpl.unpackDocumentUri(Unknown Source:52)
	at org.oxycblt.auxio.music.MusicViewModel$exportPlaylist$1.invokeSuspend(SourceFile:42)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(Unknown Source:8)
	at kotlinx.coroutines.DispatchedTask.run(Unknown Source:94)
	at androidx.core.app.ActivityRecreator$1.run(SourceFile:40)
	at kotlinx.coroutines.scheduling.TaskImpl.run(Unknown Source:2)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(SourceFile:92)
	Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@aaad05a, Dispatchers.IO]

export crash log

You cannot export to the downloads folder, Auxio cannot handle those paths. Try another folder @Wjxfi

Okey wait @OxygenCobalt

@Wjxfi
Copy link
Author

Wjxfi commented Jul 27, 2024

into another regular folders it says that it is impossible to export

@OxygenCobalt
Copy link
Owner

Please stop spamming me to get my attention @Wjxfi.

Does a folder like Music not even work?

@OxygenCobalt
Copy link
Owner

Most I can tell from your logs @Wjxfi is that Auxio is using a lot of memory and struggling to garbage collect. What phone do you use? Either Auxio has a memory leak or your phone has so little memory that it simply cannot keep your library in-memory.

@Wjxfi
Copy link
Author

Wjxfi commented Jul 28, 2024

Please stop spamming me to get my attention @Wjxfi.

Does a folder like Music not even work?

Yes

@Wjxfi
Copy link
Author

Wjxfi commented Jul 28, 2024

Most I can tell from your logs @Wjxfi is that Auxio is using a lot of memory and struggling to garbage collect. What phone do you use? Either Auxio has a memory leak or your phone has so little memory that it simply cannot keep your library in-memory.

Before the update everything worked and I have enough space. @OxygenCobalt

@OxygenCobalt
Copy link
Owner

Okay @Wjxfi, I will be sending you several APKs soon to test that will allow me to track when this issue developed. Please wait.

@foss-
Copy link

foss- commented Aug 16, 2024

I was slightly confused to see #825 set to duplicated of issue 842 here. Am I understanding correctly that the crash logs I sent in 825 have changed over the testing period?

For me the behavior still feels like a crash. But maybe it is a lag (or rather memory issue), which is causing the crash?

Do you have an idea how to tackle the remaining memory issue? Not a major issue, since I can fallback to album or artist view, but song view is mostly unusable currently.

@OxygenCobalt
Copy link
Owner

Yes @foss-, the issue changed from me failing to go foreground to something apparently allocating way too much memory.

Since I cannot reproduce this, I must bisect and generate builds from various steps of the 3.5.0 development process (with the patched foreground behavior) so that I can see if the memory issue was introduced with media3 or not. Currently I don't know, since I'm 90% sure that pre-media3 debug build had the foreground glitch still in there.

@foss-
Copy link

foss- commented Aug 17, 2024

I tested old versions to check whether 3.4.3 worked reliable. It does play tracks from Songs Category and while working rather reliably, after having Auxio open over nighty and then selecting another track from Songs it also crashed. Not sure if that is the same problem though. But after re-opening playing tracks from Songs again was possible.

@OxygenCobalt
Copy link
Owner

Can you take a bug report if it happens again @foss-? It might be that memory issue.

@foss-
Copy link

foss- commented Aug 19, 2024

Android bug report contains a bit too much personal data for my taste and is impossible to sanitize.

3.4.3 crashing when tapping song from songs category:

08-19 12:02:12.575  1730  1855 I Process : Sending signal. PID: 18483 SIG: 9
08-19 12:02:12.578  1730  1854 W ActivityManager: setHasOverlayUi called on unknown pid: 18483
08-19 12:02:12.584   950   950 E ClientCache: failed to get buffer, invalid process token
08-19 12:02:12.587   950   950 E BpTransactionCompletedListener: Failed to transact (-32)
08-19 12:02:12.593  3955  3955 I GoogleInputMethodService: GoogleInputMethodService.onFinishInput():3184 
08-19 12:02:12.595  3955  3955 I GoogleInputMethodService: GoogleInputMethodService.updateDeviceLockedStatus():2246 repeatCheckTimes = 0, locked = false
08-19 12:02:12.598  3955  3955 I GoogleInputMethodService: GoogleInputMethodService.onStartInput():1982 onStartInput(EditorInfo{EditorInfo{packageName=fr.neamar.kiss, inputType=0, inputTypeString=NULL, enableLearning=false, autoCorrection=false, autoComplete=false, imeOptions=0, privateImeOptions=null, actionName=UNSPECIFIED, actionLabel=null, initialSelStart=-1, initialSelEnd=-1, initialCapsMode=0, label=null, fieldId=-1, fieldName=null, extras=null, hintText=null, hintLocales=[]}}, false)
08-19 12:02:12.599  3955  3955 I GoogleInputMethodService: GoogleInputMethodService.updateDeviceLockedStatus():2246 repeatCheckTimes = 1, locked = false
08-19 12:02:12.600  3955  3955 I AndroidIME: InputBundleManager.loadActiveInputBundleId():450 loadActiveInputBundleId: und-Latn-x-password, password
08-19 12:02:12.684  1730  2475 D ConnectivityService: NetReassign [no changes]
08-19 12:02:12.798  1730  1854 W ActivityTaskManager: Activity top resumed state loss timeout for ActivityRecord{38d83a u0 org.oxycblt.auxio/.MainActivity} t-1 f}}
08-19 12:02:13.776   840  2325 D audio_hw_primary: out_standby: enter: stream (0xf2574800) usecase(0: deep-buffer-playback)

3.5.2 crashing when tapping song from songs category (it crashed on first tap, while 3.4.3 played a few songs and only crashed when tapping speed was increased:

android.app.ForegroundServiceStartNotAllowedException: Service.startForeground() not allowed due to mAllowStartForeground false: service org.oxycblt.auxio/.AuxioService
	at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:54)
	at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:50)
	at android.os.Parcel.readParcelableInternal(Parcel.java:4816)
	at android.os.Parcel.readParcelable(Parcel.java:4778)
	at android.os.Parcel.createExceptionOrNull(Parcel.java:3006)
	at android.os.Parcel.createException(Parcel.java:2995)
	at android.os.Parcel.readException(Parcel.java:2978)
	at android.os.Parcel.readException(Parcel.java:2920)
	at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:6114)
	at android.app.Service.startForeground(Service.java:743)
	at org.oxycblt.auxio.AuxioService.updateForeground(SourceFile:232)
	at org.oxycblt.auxio.music.service.IndexerServiceFragment.onIndexingStateChanged(SourceFile:9)
	at org.oxycblt.auxio.music.MusicRepositoryImpl.emitIndexingProgress(Unknown Source:94)
	at org.oxycblt.auxio.music.MusicRepositoryImpl$emitIndexingProgress$1.invokeSuspend(SourceFile:13)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(Unknown Source:8)
	at kotlinx.coroutines.DispatchedTask.run(Unknown Source:94)
	at androidx.core.app.ActivityRecreator$1.run(SourceFile:40)
	at kotlinx.coroutines.scheduling.TaskImpl.run(Unknown Source:2)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(SourceFile:92)

@OxygenCobalt
Copy link
Owner

There's no crash in the 3.4.3 report, is there any error messages from AndroidRuntime @foss-?

@foss-
Copy link

foss- commented Aug 19, 2024

How would I access that?

I tried to find relevant bits in logcat but can retry if those are missing. I tried that as no crash log was presented.The app closed itself while tapping songs from songs category.

@OxygenCobalt
Copy link
Owner

Okay @foss-, that means:

  1. You didn't take the bug report at the right time, and the crash log was cleared. Not sure if this is relevant.
  2. It wasn't a crash and was just...something else entirely. Sometimes if you do a weird gesture it can close the app, and if playback isn't active the app would completely shut down.

@foss-
Copy link

foss- commented Aug 21, 2024

fair, do you need additional debug output or is the 3.5.2 crash sufficient?

@OxygenCobalt
Copy link
Owner

OxygenCobalt commented Aug 21, 2024

No, I need a crash for 3.4.3 @foss-.

Regardless, since it didn't insta-crash on playback that must mean something decided to start consuming way more memory in 3.5.0. My guess is media3, because media3 has had these issues before.

@foss-
Copy link

foss- commented Aug 21, 2024

Does this include the relevant part you are looking for? This is 3.4.3 closing while being in foreground, playing a track and selecting another track from songs category.

Please download if so, will vanish in 1 week: https://bin.disroot.org/?5a8167083cd4e27c#DXBdmkyxjd65uX3s8bEzEErAySEqfDX7iKtCZM3FKnDJ

@OxygenCobalt
Copy link
Owner

So this has existed before @foss-. It seems to be a fundamental memory issue with ExoPlayer. I think I might need to benchmark Auxio's behavior on my end by multiplying out my songs library into a huge queue and seeing what happens.

If you want, keep trying older versions until the memory issue disappears (if at all). This might help me track it down better.

@OxygenCobalt
Copy link
Owner

So I went and tested an artificial 16k-song queue on dev and it worked just fine @foss-, so either my phone just has more memory, I don't have enough songs, or there's something device specific going on.

@OxygenCobalt
Copy link
Owner

So, I think the fundamental issue I'm facing here is that at libraries of @foss- and @Wjxfi's scale, and on weak/janky enough devices, Auxio's idea of reducing latency through hosting everything in-memory completely and utterly breaks down, especially now that I have to mirror everything through Media3 and how it can stack even more of it's own memory use on.

The fundamental issue though is that moving to a latency-first model also is pretty bad, it destroys any idea of snappiness unless I put an obscene amount of hours into UI retooling. And Media3 will always be a crazy memory and CPU hog until they somehow fix that or I force-revert to MediaBrowserService (which is actually extremely tempting given how poorly the Media3 move has gone so far...)

I frankly have no clue what to do here.

@foss-
Copy link

foss- commented Aug 26, 2024

3.5.3 crashes (expected)

Randomly tested 3.1.1 by just picking an old build and found response when playing tracks from Songs category is overall much more responsive. No choppy or briefly stuck sound, no lag after selecting a track for a few seconds before playback begins. I am unable to provoke a crash when quickly tapping various tracks from songs category AND I am unable to provoke a crash when using shuffle in the songs category.

@OxygenCobalt
Copy link
Owner

OxygenCobalt commented Aug 26, 2024

3.5.3 crashes (expected)

Randomly tested 3.1.1 by just picking an old build and found response when playing tracks from Songs category is overall much more responsive. No choppy or briefly stuck sound, no lag after selecting a track for a few seconds before playback begins. I am unable to provoke a crash when quickly tapping various tracks from songs category AND I am unable to provoke a crash when using shuffle in the songs category.

Okay @foss-, can you keep trying newer versions (3.2, 3.3) until things destabilize? This will get me a good idea of what the problem actually is.

@OxygenCobalt
Copy link
Owner

I heard from others that ExoPlayer's gapless playback support might also cause OOMs since big MediaItem queues can trigger way too many pending tasks. In that case I might have to make that a toggle.

@foss-
Copy link

foss- commented Aug 26, 2024

3.5.x: NOT OK
3.4.0: NOT OK
3.3.3: OK
3.3.0: OK
3.2.0: OK
3.1.1: OK

@OxygenCobalt
Copy link
Owner

OxygenCobalt commented Aug 26, 2024

Yep. It's gapless playback @foss-. That was the entire issue. The entire time. Probably @Wjxfi's problem too. Still going to dumpster Media3's session functionality since I really dislike working with it and it provides zero tangible benefits.

I need to check if there's any natural mitigation for this from the Media3 developers. Otherwise I'm going to have to either make gapless playback a setting, or dynamically turn it off when a queue is bigger than some arbitrary amount.

@OxygenCobalt OxygenCobalt changed the title Extreme lag on 3.5.0 Gapless playback is extremely laggy on large queues Aug 28, 2024
@OxygenCobalt OxygenCobalt changed the title Gapless playback is extremely laggy on large queues Large queues cause extreme lag/out-of-memory crashes Aug 28, 2024
@OxygenCobalt
Copy link
Owner

Okay, judging by discussions with maintainers I will need to make a setting for gapless playback to resolve the instability issue, at least until the media maintainers can introduce a paging-capable player.

@OxygenCobalt
Copy link
Owner

Rolling into #957.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working critical Need to get this fixed right now ui Related to app UI
Projects
Status: The Playback Update
Development

No branches or pull requests

3 participants