From 168f5dfa8944934c5aa7fd6aee676bc5aa82935b Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 9 Jun 2023 18:34:00 +0200 Subject: [PATCH] Add a 5s timeout to avoid infinite loading (actually waiting for network timeout which can be long and is harder to configure). --- .../features/login/impl/resolver/HomeserverResolver.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/features/login/impl/src/main/kotlin/io/element/android/features/login/impl/resolver/HomeserverResolver.kt b/features/login/impl/src/main/kotlin/io/element/android/features/login/impl/resolver/HomeserverResolver.kt index 8a1a72670c..a11b680f63 100644 --- a/features/login/impl/src/main/kotlin/io/element/android/features/login/impl/resolver/HomeserverResolver.kt +++ b/features/login/impl/src/main/kotlin/io/element/android/features/login/impl/resolver/HomeserverResolver.kt @@ -30,6 +30,7 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import kotlinx.coroutines.withContext +import kotlinx.coroutines.withTimeout import java.util.Collections import javax.inject.Inject @@ -56,7 +57,11 @@ class HomeserverResolver @Inject constructor( withContext(dispatchers.io) { list.map { async { - val wellKnown = tryOrNull { wellknownRequest.execute(it) } + val wellKnown = tryOrNull { + withTimeout(5000) { + wellknownRequest.execute(it) + } + } val isValid = wellKnown?.isValid().orFalse() if (isValid) { val supportSlidingSync = wellKnown?.supportSlidingSync().orFalse()