diff --git a/resolver/src/main/java/io/netty/resolver/AddressResolverGroup.java b/resolver/src/main/java/io/netty/resolver/AddressResolverGroup.java index 7020219293..6a4142e4f3 100644 --- a/resolver/src/main/java/io/netty/resolver/AddressResolverGroup.java +++ b/resolver/src/main/java/io/netty/resolver/AddressResolverGroup.java @@ -102,19 +102,19 @@ public abstract class AddressResolverGroup implements C @SuppressWarnings({ "unchecked", "SuspiciousToArrayCall" }) public void close() { final AddressResolver[] rArray; + final Map.Entry>>[] listeners; + synchronized (resolvers) { rArray = (AddressResolver[]) resolvers.values().toArray(new AddressResolver[0]); resolvers.clear(); - - for (final Map.Entry>> entry : - executorTerminationListeners.entrySet()) { - - entry.getKey().terminationFuture().removeListener(entry.getValue()); - } - + listeners = executorTerminationListeners.entrySet().toArray(new Map.Entry[0]); executorTerminationListeners.clear(); } + for (final Map.Entry>> entry : listeners) { + entry.getKey().terminationFuture().removeListener(entry.getValue()); + } + for (final AddressResolver r: rArray) { try { r.close();