Do not return dead server from ensureServerLocked

This commit is contained in:
Mygod
2020-07-28 04:47:59 +08:00
parent 84be6730ff
commit fe68f72854
2 changed files with 9 additions and 8 deletions

View File

@@ -24,7 +24,11 @@ abstract class RootSession {
private var closePending = false
private suspend fun ensureServerLocked(): RootServer {
server?.let { return it }
server?.let {
if (it.active) return it
closeLocked()
usersCount = 0
}
check(usersCount == 0L)
val server = createServer()
try {
@@ -42,6 +46,7 @@ abstract class RootSession {
}
private suspend fun closeLocked() {
closePending = false
val server = server
this.server = null
server?.close()
@@ -76,15 +81,11 @@ abstract class RootSession {
when {
!server.active -> {
usersCount = 0
closePending = false
closeLocked()
return@withLock
}
--usersCount > 0L -> return@withLock
closePending -> {
closePending = false
closeLocked()
}
closePending -> closeLocked()
else -> startTimeoutLocked()
}
}

View File

@@ -192,7 +192,7 @@ class Routing(private val caller: Any, private val downstream: String) : IpNeigh
Subrouting(priority, ifname)
} catch (e: Exception) {
SmartSnackbar.make(e).show()
Timber.w(e)
if (e !is CancellationException) Timber.w(e)
null
}
}
@@ -221,7 +221,7 @@ class Routing(private val caller: Any, private val downstream: String) : IpNeigh
Subrouting(priority)
} catch (e: Exception) {
SmartSnackbar.make(e).show()
Timber.w(e)
if (e !is CancellationException) Timber.w(e)
null
}
dns = listOf(parseNumericAddress("8.8.8.8"))