Commit 6570c098 authored by Mygod's avatar Mygod

Log remote resolving time out

parent 6b9f2245
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
package com.github.shadowsocks.net package com.github.shadowsocks.net
import android.util.Log import android.util.Log
import com.crashlytics.android.Crashlytics
import com.github.shadowsocks.utils.printLog import com.github.shadowsocks.utils.printLog
import kotlinx.coroutines.* import kotlinx.coroutines.*
import org.xbill.DNS.* import org.xbill.DNS.*
...@@ -54,6 +55,7 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd ...@@ -54,6 +55,7 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
var localIpMatcher: List<Subnet> = emptyList() var localIpMatcher: List<Subnet> = emptyList()
companion object { companion object {
private const val TAG = "LocalDnsServer"
private const val TIMEOUT = 10_000L private const val TIMEOUT = 10_000L
/** /**
* TTL returned from localResolver is set to 120. Android API does not provide TTL, * TTL returned from localResolver is set to 120. Android API does not provide TTL,
...@@ -107,7 +109,7 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd ...@@ -107,7 +109,7 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
val localResults = try { val localResults = try {
withTimeout(TIMEOUT) { GlobalScope.async(Dispatchers.IO) { localResolver(host) }.await() } withTimeout(TIMEOUT) { GlobalScope.async(Dispatchers.IO) { localResolver(host) }.await() }
} catch (_: TimeoutCancellationException) { } catch (_: TimeoutCancellationException) {
Log.w("LocalDnsServer", "Local resolving timed out, falling back to remote resolving") Crashlytics.log(Log.WARN, TAG, "Local resolving timed out, falling back to remote resolving")
return@coroutineScope remote.await() return@coroutineScope remote.await()
} catch (_: UnknownHostException) { } catch (_: UnknownHostException) {
return@coroutineScope remote.await() return@coroutineScope remote.await()
...@@ -124,9 +126,13 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd ...@@ -124,9 +126,13 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
}, Section.ANSWER) }, Section.ANSWER)
}.toWire()) }.toWire())
} else remote.await() } else remote.await()
} catch (e: IOException) { } catch (e: Exception) {
remote.cancel() remote.cancel()
printLog(e) when (e) {
is TimeoutCancellationException -> Crashlytics.log(Log.WARN, TAG, "Remote resolving timed out")
is CancellationException -> { } // ignore
else -> printLog(e)
}
ByteBuffer.wrap(prepareDnsResponse(request).apply { ByteBuffer.wrap(prepareDnsResponse(request).apply {
header.rcode = Rcode.SERVFAIL header.rcode = Rcode.SERVFAIL
}.toWire()) }.toWire())
......
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