Record stats before exit

This commit is contained in:
Mygod
2018-10-02 22:41:43 +08:00
parent 8419734df8
commit 5f5bb063c0

View File

@@ -130,6 +130,7 @@ class Routing(private val owner: Context, val upstream: String?, private val dow
}
fun revert() {
stop()
TrafficRecorder.update() // record stats before exiting to prevent stats losing
synchronized(subroutes) { subroutes.forEach { (_, subroute) -> subroute.close() } }
transaction.revert()
}
@@ -145,7 +146,10 @@ class Routing(private val owner: Context, val upstream: String?, private val dow
synchronized(subroutes) {
val toRemove = HashSet(subroutes.keys)
for (client in it) if (!client.record.blocked) updateForClient(client, toRemove)
for (address in toRemove) subroutes.remove(address)!!.close()
if (toRemove.isNotEmpty()) {
TrafficRecorder.update() // record stats before removing rules to prevent stats losing
for (address in toRemove) subroutes.remove(address)!!.close()
}
}
}
}