# ConcurrentModificationException including patch.

**URL:** <https://discuss.elastic.co/t/concurrentmodificationexception-including-patch/4347>\
**Category:** Elasticsearch\
**Created:** [May 4, 2011, 4:52pm UTC](https://discuss.elastic.co/t/concurrentmodificationexception-including-patch/4347 "2011-05-04T16:52:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michel\_Conrad](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michel\_Conrad](https://discuss.elastic.co/u/Michel_Conrad)\
**Post date:** [May 4, 2011, 4:52pm UTC](https://discuss.elastic.co/t/concurrentmodificationexception-including-patch/4347/1 "2011-05-04T16:52:54Z")

</div>

Hi, I got the following exception.

java.util.ConcurrentModificationException  
at java.util.HashMap$HashIterator.nextEntry(HashMap.java:793)  
at java.util.HashMap$KeyIterator.next(HashMap.java:828)  
at org.elasticsearch.gateway.local.LocalGatewayNodeAllocation.buildShardStores(LocalGatewayNodeAllocation.java:353)  
at org.elasticsearch.gateway.local.LocalGatewayNodeAllocation.allocateUnassigned(LocalGatewayNodeAllocation.java:213)  
at org.elasticsearch.cluster.routing.allocation.NodeAllocations.allocateUnassigned(NodeAllocations.java:80)  
at org.elasticsearch.cluster.routing.allocation.ShardsAllocation.reroute(ShardsAllocation.java:147)  
at org.elasticsearch.cluster.routing.allocation.ShardsAllocation.reroute(ShardsAllocation.java:99)  
at org.elasticsearch.cluster.routing.RoutingService$RoutingTableUpdater$1.execute(RoutingService.java:124)  
at org.elasticsearch.cluster.service.InternalClusterService$2.run(InternalClusterService.java:175)  
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)  
at java.lang.Thread.run(Thread.java:662)

I think it should look like this:

--- a/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/local/LocalGatewayNodeAllocation.java  
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/local/LocalGatewayNodeAllocation.java  
@@ -350,9 +350,10 @@ public class LocalGatewayNodeAllocation extends  
NodeAllocation {  
} else {  
nodesIds = Sets.newHashSet();  
// clean nodes that have failed

- 

```
       for (DiscoveryNode node : shardStores.keySet()) {

```

- 

```
           if (!nodes.nodeExists(node.id())) {

```

- 

```
               shardStores.remove(node);

```

- 

```
       for (Iterator<DiscoveryNode> i =

```

shardStores.keySet().iterator(); i.hasNext()😉 {

- 

```
   	    DiscoveryNode node = i.next();

```

- 

```
   	    if (!nodes.nodeExists(node.id())) {

```

- 

```
               i.remove();
           }
       }
```

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [May 4, 2011, 5:51pm UTC](https://discuss.elastic.co/t/concurrentmodificationexception-including-patch/4347/2 "2011-05-04T17:51:33Z")

</div>

Heya, yea, it used to be a CHM, but there was no need for a concurrent version, and then this bug was introduced... . Here is the issue: [Failure when applying failed shards during local gateway allocation · Issue #903 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/903), fixed in 0.16 and master.  
On Wednesday, May 4, 2011 at 7:52 PM, Michel Conrad wrote:

> --- a/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/local/LocalGatewayNodeAllocation.java  
> +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/local/LocalGatewayNodeAllocation.java  
> @@ -350,9 +350,10 @@ public class LocalGatewayNodeAllocation extends  
> NodeAllocation {  
> } else {  
> nodesIds = Sets.newHashSet();  
> // clean nodes that have failed
> 
> - for (DiscoveryNode node : shardStores.keySet()) {
> - if (!nodes.nodeExists(node.id())) {
> - shardStores.remove(node);
> 
> - for (Iterator i =  
> shardStores.keySet().iterator(); i.hasNext()😉 {
> - DiscoveryNode node = i.next();
> - if (!nodes.nodeExists(node.id())) {
> - i.remove();  
> }  
> }

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 4:06am UTC](https://discuss.elastic.co/t/concurrentmodificationexception-including-patch/4347/3 "2017-07-06T04:06:56Z")

</div>


