Skip to content

Commit 4da9b2c

Browse files
Gianni O'Neilldadoonet
authored andcommitted
Catch AmazonClientExceptions to prevent connection loss
If the AWS client throws an exception (e.g: because of a DNS failure) it will end up killing the rejoin thread and stop retrying which can lead to a node getting stuck unable to rejoin the cluster. Closes elastic#30.
1 parent 906326d commit 4da9b2c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/main/java/org/elasticsearch/discovery/ec2/AwsEc2UnicastHostsProvider.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.discovery.ec2;
2121

22+
import com.amazonaws.AmazonClientException;
2223
import com.amazonaws.services.ec2.AmazonEC2;
2324
import com.amazonaws.services.ec2.model.*;
2425
import org.elasticsearch.Version;
@@ -96,7 +97,14 @@ public AwsEc2UnicastHostsProvider(Settings settings, TransportService transportS
9697
public List<DiscoveryNode> buildDynamicNodes() {
9798
List<DiscoveryNode> discoNodes = Lists.newArrayList();
9899

99-
DescribeInstancesResult descInstances = client.describeInstances(new DescribeInstancesRequest());
100+
DescribeInstancesResult descInstances;
101+
try {
102+
descInstances = client.describeInstances(new DescribeInstancesRequest());
103+
} catch (AmazonClientException e) {
104+
logger.info("Exception while retrieving instance list from AWS API: {}", e.getMessage());
105+
logger.debug("Full exception:", e);
106+
return discoNodes;
107+
}
100108

101109
logger.trace("building dynamic unicast discovery nodes...");
102110
for (Reservation reservation : descInstances.getReservations()) {

0 commit comments

Comments
 (0)