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
import android.os.Handler
import android.os.HandlerThread
import androidx.core.os.BuildCompat
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.suspendCancellableCoroutine
import java.net.InetAddress
import kotlin.coroutines.resume
......@@ -40,7 +43,8 @@ sealed class DnsResolverCompat {
abstract suspend fun resolve(network: Network, host: String): Array<InetAddress>
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)
......
......@@ -91,8 +91,7 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
if (profile.host.parseNumericAddress() == null) {
var retries = 0
while (true) try {
val io = GlobalScope.async(Dispatchers.IO) { service.resolver(profile.host) }
profile.host = io.await().firstOrNull()?.hostAddress ?: throw UnknownHostException()
profile.host = service.resolver(profile.host).firstOrNull()?.hostAddress ?: throw UnknownHostException()
return
} catch (e: UnknownHostException) {
// 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
val host = question.name.toString(true)
if (remoteDomainMatcher?.containsMatchIn(host) == true) return@supervisorScope remote.await()
val localResults = try {
withTimeout(TIMEOUT) { GlobalScope.async(Dispatchers.IO) { localResolver(host) }.await() }
withTimeout(TIMEOUT) { localResolver(host) }
} catch (_: TimeoutCancellationException) {
Crashlytics.log(Log.WARN, TAG, "Local resolving timed out, falling back to remote resolving")
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