Fix ConcurrentModification
This commit is contained in:
@@ -330,7 +330,7 @@ class Routing(private val caller: Any, private val downstream: String) : IpNeigh
|
||||
stop()
|
||||
Timber.i("Stopped routing for $downstream by $caller")
|
||||
TrafficRecorder.update() // record stats before exiting to prevent stats losing
|
||||
clients.values.forEach { it.close() }
|
||||
synchronized(this) { clients.values.forEach { it.close() } }
|
||||
currentDns?.transaction?.revert()
|
||||
fallbackUpstream.subrouting?.transaction?.revert()
|
||||
upstream.subrouting?.transaction?.revert()
|
||||
|
||||
@@ -6,14 +6,13 @@ import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import java.net.InetAddress
|
||||
import java.util.*
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
class IpNeighbourMonitor private constructor() : IpMonitor() {
|
||||
companion object {
|
||||
private val callbacks = Collections.newSetFromMap(ConcurrentHashMap<Callback, Boolean>())
|
||||
private val callbacks = mutableSetOf<Callback>()
|
||||
var instance: IpNeighbourMonitor? = null
|
||||
|
||||
fun registerCallback(callback: Callback) = synchronized(this) {
|
||||
fun registerCallback(callback: Callback) = synchronized(callbacks) {
|
||||
if (!callbacks.add(callback)) return@synchronized
|
||||
var monitor = instance
|
||||
if (monitor == null) {
|
||||
@@ -24,7 +23,7 @@ class IpNeighbourMonitor private constructor() : IpMonitor() {
|
||||
callback.onIpNeighbourAvailable(synchronized(monitor.neighbours) { monitor.neighbours.values.toList() })
|
||||
}
|
||||
}
|
||||
fun unregisterCallback(callback: Callback) = synchronized(this) {
|
||||
fun unregisterCallback(callback: Callback) = synchronized(callbacks) {
|
||||
if (!callbacks.remove(callback) || callbacks.isNotEmpty()) return@synchronized
|
||||
instance?.destroy()
|
||||
instance = null
|
||||
@@ -68,8 +67,10 @@ class IpNeighbourMonitor private constructor() : IpMonitor() {
|
||||
updatePosted = false
|
||||
neighbours.values.toList()
|
||||
}
|
||||
synchronized(callbacks) {
|
||||
for (callback in callbacks) callback.onIpNeighbourAvailable(neighbours)
|
||||
}
|
||||
}
|
||||
updatePosted = true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user