From 6e2c653c6eb68464e386799c6f05710db39826c7 Mon Sep 17 00:00:00 2001 From: junyulai Date: Mon, 13 May 2019 14:19:00 +0800 Subject: [PATCH] Fix concurrent modification exception in KeepaliveTracker In aosp/951200, the clean up function delete the item in the hash map that holds the record while iterating it, where the list used to iterate the records is backed by the hash map, so changes to the map are reflected in the list and caused the concurrent modification exception. Bug: 132341736 Test: 1. atest com.android.server.ConnectivityServiceTest \ #testNattSocketKeepalives --generate-new-metrics 300 2. atest FrameworksNetTests --generate-new-metrics 10 Change-Id: I0481a469ee23231e5f0ab738a06b5e09f6cdb680 --- .../com/android/server/connectivity/KeepaliveTracker.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/connectivity/KeepaliveTracker.java b/services/core/java/com/android/server/connectivity/KeepaliveTracker.java index 526b4ffabb..e10d737335 100644 --- a/services/core/java/com/android/server/connectivity/KeepaliveTracker.java +++ b/services/core/java/com/android/server/connectivity/KeepaliveTracker.java @@ -462,9 +462,10 @@ public class KeepaliveTracker { } public void handleStopAllKeepalives(NetworkAgentInfo nai, int reason) { - HashMap networkKeepalives = mKeepalives.get(nai); + final HashMap networkKeepalives = mKeepalives.get(nai); if (networkKeepalives != null) { - for (KeepaliveInfo ki : networkKeepalives.values()) { + final ArrayList kalist = new ArrayList(networkKeepalives.values()); + for (KeepaliveInfo ki : kalist) { ki.stop(reason); // Clean up keepalives since the network agent is disconnected and unable to pass // back asynchronous result of stop().