Skip to content

Commit f290c59

Browse files
committed
properly clean up if inner tribe fails to initialize
1 parent fdcc93a commit f290c59

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

modules/tribe/src/main/java/org/elasticsearch/tribe/TribeService.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.logging.log4j.util.Supplier;
2424
import org.apache.lucene.util.BytesRef;
2525
import org.elasticsearch.ElasticsearchException;
26+
import org.elasticsearch.ExceptionsHelper;
2627
import org.elasticsearch.cluster.ClusterChangedEvent;
2728
import org.elasticsearch.cluster.ClusterState;
2829
import org.elasticsearch.cluster.ClusterStateListener;
@@ -165,7 +166,20 @@ public TribeService(Settings settings, Environment environment, NodeEnvironment
165166
nodesSettings.remove("on_conflict"); // remove prefix settings that don't indicate a client
166167
for (Map.Entry<String, Settings> entry : nodesSettings.entrySet()) {
167168
Settings clientSettings = buildClientSettings(entry.getKey(), nodeEnvironment.nodeId(), settings, entry.getValue());
168-
nodes.add(clientNodeBuilder.newNode(clientSettings, environment.configFile()));
169+
try {
170+
nodes.add(clientNodeBuilder.newNode(clientSettings, environment.configFile()));
171+
} catch (Exception e) {
172+
// calling close is safe for non started nodes, we can just iterate over all
173+
for (Node otherNode : nodes) {
174+
try {
175+
otherNode.close();
176+
} catch (Exception inner) {
177+
inner.addSuppressed(e);
178+
logger.warn((Supplier<?>) () -> new ParameterizedMessage("failed to close node {} on failed start", otherNode), inner);
179+
}
180+
}
181+
throw ExceptionsHelper.convertToRuntime(e);
182+
}
169183
}
170184

171185
this.blockIndicesMetadata = BLOCKS_METADATA_INDICES_SETTING.get(settings).toArray(Strings.EMPTY_ARRAY);
@@ -237,10 +251,7 @@ public void startNodes() {
237251
logger.warn((Supplier<?>) () -> new ParameterizedMessage("failed to close node {} on failed start", otherNode), inner);
238252
}
239253
}
240-
if (e instanceof RuntimeException) {
241-
throw (RuntimeException) e;
242-
}
243-
throw new ElasticsearchException(e);
254+
throw ExceptionsHelper.convertToRuntime(e);
244255
}
245256
}
246257
}

0 commit comments

Comments
 (0)