Commit 4f3c8c4b authored by Mygod's avatar Mygod

Fix UnknownHostException on Chrome OS on restart

parent c08fc40d
......@@ -22,6 +22,8 @@ package com.github.shadowsocks.bg
import android.content.Context
import android.util.Base64
import android.util.Log
import com.crashlytics.android.Crashlytics
import com.github.shadowsocks.Core
import com.github.shadowsocks.acl.Acl
import com.github.shadowsocks.acl.AclSyncer
......@@ -82,7 +84,17 @@ 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 = withTimeoutOrNull(10_000) {
GlobalScope.async(Dispatchers.IO) { service.resolver(profile.host) }.await().firstOrNull()
var retries = 0
while (isActive) try {
val io = GlobalScope.async(Dispatchers.IO) { service.resolver(profile.host) }
return@withTimeoutOrNull io.await().firstOrNull()
} catch (e: UnknownHostException) {
// retries are only needed on Chrome OS where arc0 is brought up/down during VPN changes
if (!DataStore.hasArc0) throw e
Thread.yield()
Crashlytics.log(Log.WARN, "ProxyInstance-resolver", "Retry resolving attempt #${++retries}")
}
null // only here for type resolving
}?.hostAddress ?: throw UnknownHostException()
}
......
......@@ -70,7 +70,7 @@ object DataStore : OnPreferenceDataStoreChangeListener {
* An alternative way to detect this interface could be checking MAC address = 00:ff:aa:00:00:55, but there is no
* reliable way of getting MAC address for now.
*/
private val hasArc0 by lazy {
val hasArc0 by lazy {
var retry = 0
while (retry < 5) {
try {
......
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