Commit ebda36ee authored by Mygod's avatar Mygod

Do not complete local resolving in IO dispatchers on Q

parent f141dfb3
...@@ -26,6 +26,9 @@ import android.net.Network ...@@ -26,6 +26,9 @@ import android.net.Network
import android.os.Handler import android.os.Handler
import android.os.HandlerThread import android.os.HandlerThread
import androidx.core.os.BuildCompat import androidx.core.os.BuildCompat
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.suspendCancellableCoroutine import kotlinx.coroutines.suspendCancellableCoroutine
import java.net.InetAddress import java.net.InetAddress
import kotlin.coroutines.resume import kotlin.coroutines.resume
...@@ -40,7 +43,8 @@ sealed class DnsResolverCompat { ...@@ -40,7 +43,8 @@ sealed class DnsResolverCompat {
abstract suspend fun resolve(network: Network, host: String): Array<InetAddress> abstract suspend fun resolve(network: Network, host: String): Array<InetAddress>
private object DnsResolverCompat21 : DnsResolverCompat() { private object DnsResolverCompat21 : DnsResolverCompat() {
override suspend fun resolve(network: Network, host: String) = network.getAllByName(host) override suspend fun resolve(network: Network, host: String) =
GlobalScope.async(Dispatchers.IO) { network.getAllByName(host) }.await()
} }
@TargetApi(29) @TargetApi(29)
......
...@@ -91,8 +91,7 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro ...@@ -91,8 +91,7 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
if (profile.host.parseNumericAddress() == null) { if (profile.host.parseNumericAddress() == null) {
var retries = 0 var retries = 0
while (true) try { while (true) try {
val io = GlobalScope.async(Dispatchers.IO) { service.resolver(profile.host) } profile.host = service.resolver(profile.host).firstOrNull()?.hostAddress ?: throw UnknownHostException()
profile.host = io.await().firstOrNull()?.hostAddress ?: throw UnknownHostException()
return return
} catch (e: UnknownHostException) { } catch (e: UnknownHostException) {
// retries are only needed on Chrome OS where arc0 is brought up/down during VPN changes // retries are only needed on Chrome OS where arc0 is brought up/down during VPN changes
......
...@@ -108,7 +108,7 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd ...@@ -108,7 +108,7 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
val host = question.name.toString(true) val host = question.name.toString(true)
if (remoteDomainMatcher?.containsMatchIn(host) == true) return@supervisorScope remote.await() if (remoteDomainMatcher?.containsMatchIn(host) == true) return@supervisorScope remote.await()
val localResults = try { val localResults = try {
withTimeout(TIMEOUT) { GlobalScope.async(Dispatchers.IO) { localResolver(host) }.await() } withTimeout(TIMEOUT) { localResolver(host) }
} catch (_: TimeoutCancellationException) { } catch (_: TimeoutCancellationException) {
Crashlytics.log(Log.WARN, TAG, "Local resolving timed out, falling back to remote resolving") Crashlytics.log(Log.WARN, TAG, "Local resolving timed out, falling back to remote resolving")
return@supervisorScope remote.await() return@supervisorScope remote.await()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment