Commit d6d6447d authored by Mygod's avatar Mygod

Launch resolver in GlobalScope instead

We do not wish to wait for resolver threads which can block for a long time.
parent 4344883b
......@@ -34,9 +34,7 @@ import com.github.shadowsocks.utils.DirectBoot
import com.github.shadowsocks.utils.disconnectFromMain
import com.github.shadowsocks.utils.parseNumericAddress
import com.github.shadowsocks.utils.signaturesCompat
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import kotlinx.coroutines.withTimeout
import kotlinx.coroutines.*
import java.io.File
import java.io.IOException
import java.net.HttpURLConnection
......@@ -85,7 +83,7 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
// it's hard to resolve DNS on a specific interface so we'll do it here
if (profile.host.parseNumericAddress() == null) profile.host = withTimeout(10_000) {
withContext(Dispatchers.IO) { resolver(profile.host).first().hostAddress }
GlobalScope.async(Dispatchers.IO) { resolver(profile.host).first().hostAddress }.await()
} ?: throw UnknownHostException()
}
......
......@@ -96,7 +96,7 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
val host = question.name.toString(true)
if (remoteDomainMatcher?.containsMatchIn(host) == true) return remote.await()
val localResults = try {
withTimeout(TIMEOUT) { withContext(Dispatchers.IO) { localResolver(host) } }
withTimeout(TIMEOUT) { GlobalScope.async(Dispatchers.IO) { localResolver(host) }.await() }
} catch (_: TimeoutCancellationException) {
Log.w("LocalDnsServer", "Local resolving timed out, falling back to remote resolving")
return 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