From c5caeaea740e9b1a7a5da35e856bebbd947449c6 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Sat, 21 Jul 2012 23:02:07 +0200 Subject: [PATCH] Duplicate channel futures list before closing channels. Resolves issue 221 --- .../src/main/java/com/google/bitcoin/core/PeerGroup.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/google/bitcoin/core/PeerGroup.java b/core/src/main/java/com/google/bitcoin/core/PeerGroup.java index a02d62671..8bf38b5a5 100644 --- a/core/src/main/java/com/google/bitcoin/core/PeerGroup.java +++ b/core/src/main/java/com/google/bitcoin/core/PeerGroup.java @@ -501,10 +501,13 @@ public class PeerGroup { synchronized (PeerGroup.this) { running = false; shutdownPeerDiscovery(); + LinkedList futures; synchronized (channelFutures) { - for (ChannelFuture future : channelFutures.values()) { - future.getChannel().close(); - } + // Copy the list here because the act of closing the channel modifies the channelFutures map. + futures = new LinkedList(channelFutures.values()); + } + for (ChannelFuture future : futures) { + future.getChannel().close(); } bootstrap.releaseExternalResources(); }