Browse Source

Increase timeout duration of WebViewInterceptors (#8099)

AntsyLich 2 years ago
parent
commit
e2ce3f68bf

+ 1 - 4
core/src/main/java/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt

@@ -18,7 +18,6 @@ import okhttp3.Response
 import uy.kohesive.injekt.injectLazy
 import java.io.IOException
 import java.util.concurrent.CountDownLatch
-import java.util.concurrent.TimeUnit
 
 class CloudflareInterceptor(private val context: Context) : WebViewInterceptor(context) {
 
@@ -109,9 +108,7 @@ class CloudflareInterceptor(private val context: Context) : WebViewInterceptor(c
             webview?.loadUrl(origRequestUrl, headers)
         }
 
-        // Wait a reasonable amount of time to retrieve the solution. The minimum should be
-        // around 4 seconds but it can take more due to slow networks or server issues.
-        latch.await(12, TimeUnit.SECONDS)
+        latch.awaitFor30Seconds()
 
         executor.execute {
             if (!cloudflareBypassed) {

+ 1 - 2
core/src/main/java/eu/kanade/tachiyomi/network/interceptor/Http103Interceptor.kt

@@ -15,7 +15,6 @@ import okhttp3.Response
 import okhttp3.ResponseBody.Companion.toResponseBody
 import java.io.IOException
 import java.util.concurrent.CountDownLatch
-import java.util.concurrent.TimeUnit
 
 // TODO: Remove when OkHttp can handle HTTP 103 responses
 class Http103Interceptor(context: Context) : WebViewInterceptor(context) {
@@ -76,7 +75,7 @@ class Http103Interceptor(context: Context) : WebViewInterceptor(context) {
             webview?.loadUrl(requestUrl, headers)
         }
 
-        latch.await(10, TimeUnit.SECONDS)
+        latch.awaitFor30Seconds()
 
         executor.execute {
             webview?.run {

+ 6 - 0
core/src/main/java/eu/kanade/tachiyomi/network/interceptor/WebViewInterceptor.kt

@@ -18,6 +18,8 @@ import okhttp3.Request
 import okhttp3.Response
 import uy.kohesive.injekt.injectLazy
 import java.util.Locale
+import java.util.concurrent.CountDownLatch
+import java.util.concurrent.TimeUnit
 
 abstract class WebViewInterceptor(private val context: Context) : Interceptor {
 
@@ -71,6 +73,10 @@ abstract class WebViewInterceptor(private val context: Context) : Interceptor {
             .mapValues { it.value.getOrNull(0).orEmpty() }
     }
 
+    fun CountDownLatch.awaitFor30Seconds() {
+        await(30, TimeUnit.SECONDS)
+    }
+
     fun createWebView(request: Request): WebView {
         return WebView(context).apply {
             setDefaultSettings()