From c7e79dfb6abc69ffed9c994dd0f2cc2e218d19a9 Mon Sep 17 00:00:00 2001 From: Mygod Date: Thu, 4 Oct 2018 19:45:54 +0800 Subject: [PATCH] Allow unregister to fail Race condition might occur when cleaning. --- .../java/be/mygod/vpnhotspot/net/monitor/TrafficRecorder.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/TrafficRecorder.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/TrafficRecorder.kt index cbef0f28..fd1d0e3f 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/TrafficRecorder.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/TrafficRecorder.kt @@ -37,7 +37,8 @@ object TrafficRecorder { } fun unregister(ip: InetAddress, upstream: String?, downstream: String) = synchronized(this) { update() // flush stats before removing - check(records.remove(Triple(ip, upstream, downstream)) != null) + if (records.remove(Triple(ip, upstream, downstream)) == null) Timber.w( + "Failed to find traffic record for ($ip, $downstream, $upstream).") } private fun unscheduleUpdateLocked() {