From 67307665041f5a36f6805b97f0f1cbd9865d9012 Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Sun, 28 Jan 2024 21:37:20 -0700 Subject: [PATCH] music: increase music load timeout TagExtractor can take longer than 10 seconds to load, increase it to 60 seconds. --- .../main/java/org/oxycblt/auxio/music/MusicRepository.kt | 5 +++-- app/src/main/java/org/oxycblt/auxio/util/StateUtil.kt | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/oxycblt/auxio/music/MusicRepository.kt b/app/src/main/java/org/oxycblt/auxio/music/MusicRepository.kt index 97ecaa7fd..459c8fcbb 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/MusicRepository.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/MusicRepository.kt @@ -42,6 +42,7 @@ import org.oxycblt.auxio.music.metadata.Separators import org.oxycblt.auxio.music.metadata.TagExtractor import org.oxycblt.auxio.music.user.MutableUserLibrary import org.oxycblt.auxio.music.user.UserLibrary +import org.oxycblt.auxio.util.DEFAULT_TIMEOUT import org.oxycblt.auxio.util.forEachWithTimeout import org.oxycblt.auxio.util.logD import org.oxycblt.auxio.util.logE @@ -481,7 +482,7 @@ constructor( val rawSongs = LinkedList() // Use a longer timeout so that dependent components can timeout and throw errors that // provide more context than if we timed out here. - processedSongs.forEachWithTimeout(20000) { + processedSongs.forEachWithTimeout(DEFAULT_TIMEOUT * 2) { rawSongs.add(it) // Since discovery takes up the bulk of the music loading process, we switch to // indicating a defined amount of loaded songs in comparison to the projected amount @@ -489,7 +490,7 @@ constructor( emitIndexingProgress(IndexingProgress.Songs(rawSongs.size, query.projectedTotal)) } - withTimeout(10000) { + withTimeout(DEFAULT_TIMEOUT) { mediaStoreJob.await() tagJob.await() } diff --git a/app/src/main/java/org/oxycblt/auxio/util/StateUtil.kt b/app/src/main/java/org/oxycblt/auxio/util/StateUtil.kt index 6e60eadf2..d723dd5e3 100644 --- a/app/src/main/java/org/oxycblt/auxio/util/StateUtil.kt +++ b/app/src/main/java/org/oxycblt/auxio/util/StateUtil.kt @@ -152,6 +152,8 @@ private fun Fragment.launch( viewLifecycleOwner.lifecycleScope.launch { viewLifecycleOwner.repeatOnLifecycle(state, block) } } +const val DEFAULT_TIMEOUT = 60000L + /** * Wraps [SendChannel.send] with a specified timeout. * @@ -160,7 +162,7 @@ private fun Fragment.launch( * @throws TimeoutException If the timeout is reached, provides context on what element * specifically. */ -suspend fun SendChannel.sendWithTimeout(element: E, timeout: Long = 10000) { +suspend fun SendChannel.sendWithTimeout(element: E, timeout: Long = DEFAULT_TIMEOUT) { try { withTimeout(timeout) { send(element) } } catch (e: TimeoutCancellationException) { @@ -179,7 +181,7 @@ suspend fun SendChannel.sendWithTimeout(element: E, timeout: Long = 10000 * specifically. */ suspend fun ReceiveChannel.forEachWithTimeout( - timeout: Long = 10000, + timeout: Long = DEFAULT_TIMEOUT, action: suspend (E) -> Unit ) { var exhausted = false