# Java client retrying to connect to cluster fails and breaks cluster

**URL:** https://discuss.elastic.co/t/java-client-retrying-to-connect-to-cluster-fails-and-breaks-cluster/14121
**Category:** Elasticsearch
**Created:** [October 25, 2013, 9:29pm UTC](https://discuss.elastic.co/t/java-client-retrying-to-connect-to-cluster-fails-and-breaks-cluster/14121 "2013-10-25T21:29:15Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Jonas\_K](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jonas_k/32/2019_2.png) [@Jonas\_K](https://discuss.elastic.co/u/Jonas_K)
#### Post date: [October 25, 2013, 9:29pm UTC](https://discuss.elastic.co/t/java-client-retrying-to-connect-to-cluster-fails-and-breaks-cluster/14121/1 "2013-10-25T21:29:15Z")

</div>

I have a Java client that tries to connect to a cluster on startup. I would  
like to set it up  
so that if the cluster is not running, the client retries the connection  
(after a suitable delay), until  
the cluster is started.  
If I have multicast enabled, the program works. If unicast is used,  
however, the client fails to connect  
even after the cluster is restarted. I get:  
org.elasticsearch.cluster.block.ClusterBlockException: blocked by:  
[SERVICE\_UNAVAILABLE/1/state not recovered /  
initialized];[SERVICE\_UNAVAILABLE/2/no master]

I have to restart the cluster and the client in order for the connection to  
succeed.

Is there a way to make this work without enabling multicast?

\_jonas

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)
#### Post date: [October 25, 2013, 10:45pm UTC](https://discuss.elastic.co/t/java-client-retrying-to-connect-to-cluster-fails-and-breaks-cluster/14121/2 "2013-10-25T22:45:38Z")

</div>

How are you initializing the client? Via the TransportClient or the  
NodeClient. Make sure you are in client mode if using the NodeClient.

Cheers,

Ivan

On Fri, Oct 25, 2013 at 2:29 PM, Jonas K [thejonas@gmail.com](mailto:thejonas@gmail.com) wrote:

> I have a Java client that tries to connect to a cluster on startup. I  
> would like to set it up  
> so that if the cluster is not running, the client retries the connection  
> (after a suitable delay), until  
> the cluster is started.  
> If I have multicast enabled, the program works. If unicast is used,  
> however, the client fails to connect  
> even after the cluster is restarted. I get:  
> org.elasticsearch.cluster.block.ClusterBlockException: blocked by:  
> [SERVICE\_UNAVAILABLE/1/state not recovered /  
> initialized];[SERVICE\_UNAVAILABLE/2/no master]
> 
> I have to restart the cluster and the client in order for the connection  
> to succeed.
> 
> Is there a way to make this work without enabling multicast?
> 
> \_jonas
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Jonas\_K](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jonas_k/32/2019_2.png) [@Jonas\_K](https://discuss.elastic.co/u/Jonas_K)
#### Post date: [October 26, 2013, 1:25am UTC](https://discuss.elastic.co/t/java-client-retrying-to-connect-to-cluster-fails-and-breaks-cluster/14121/3 "2013-10-26T01:25:06Z")

</div>

On Friday, October 25, 2013 6:45:38 PM UTC-4, Ivan Brusic wrote:

> How are you initializing the client? Via the TransportClient or the  
> NodeClient. Make sure you are in client mode if using the NodeClient.

I'm using the NodeClient with

node.master: false  
node.data: false  
node.client: true

and  
discovery:  
zen:  
ping:  
multicast:  
enabled: false  
unicast:  
hosts: 127.0.0.1[9300-9400]

\_jonas

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)
#### Post date: [October 26, 2013, 7:54pm UTC](https://discuss.elastic.co/t/java-client-retrying-to-connect-to-cluster-fails-and-breaks-cluster/14121/4 "2013-10-26T19:54:28Z")

</div>

Does unicast on 127.0.0.1 really make any sense?

Jörg

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Jonas\_K](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jonas_k/32/2019_2.png) [@Jonas\_K](https://discuss.elastic.co/u/Jonas_K)
#### Post date: [October 26, 2013, 8:17pm UTC](https://discuss.elastic.co/t/java-client-retrying-to-connect-to-cluster-fails-and-breaks-cluster/14121/5 "2013-10-26T20:17:07Z")

</div>

On Saturday, October 26, 2013 3:54:28 PM UTC-4, Jörg Prante wrote:

> Does unicast on 127.0.0.1 really make any sense?

I don't know - it's what we're using for development and testing on our  
development machines.  
What would be a better approach?

thanks,  
\_jonas

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)
#### Post date: [October 26, 2013, 9:56pm UTC](https://discuss.elastic.co/t/java-client-retrying-to-connect-to-cluster-fails-and-breaks-cluster/14121/6 "2013-10-26T21:56:27Z")

</div>

You have to ensure that UDP for unicast ping is open on 127.0.0.1

I'd prefer a TransportClient connecting to 127.0.0.1:9300, that is, no UDP  
for unicast ping, just TCP.

Jörg

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Jonas\_K](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jonas_k/32/2019_2.png) [@Jonas\_K](https://discuss.elastic.co/u/Jonas_K)
#### Post date: [October 28, 2013, 11:10pm UTC](https://discuss.elastic.co/t/java-client-retrying-to-connect-to-cluster-fails-and-breaks-cluster/14121/7 "2013-10-28T23:10:28Z")

</div>

On Saturday, October 26, 2013 5:56:27 PM UTC-4, Jörg Prante wrote:

> I'd prefer a TransportClient connecting to 127.0.0.1:9300, that is, no  
> UDP for unicast ping, just TCP.

Converting to a TransportClient seems to have worked - thanks!  
\_jonas

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:10am UTC](https://discuss.elastic.co/t/java-client-retrying-to-connect-to-cluster-fails-and-breaks-cluster/14121/8 "2017-07-06T02:10:06Z")

</div>


