Skip to content

Commit af3091f

Browse files
Address review comment: wrap ETE to make it recognisable by ExceptionsHelper.isRemoteUnavailableException()
1 parent 2e03e6e commit af3091f

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

server/src/internalClusterTest/java/org/elasticsearch/indices/cluster/RemoteFieldCapsForceConnectTimeoutIT.java

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

1010
package org.elasticsearch.indices.cluster;
1111

12+
import org.elasticsearch.ElasticsearchTimeoutException;
1213
import org.elasticsearch.action.fieldcaps.FieldCapabilitiesRequest;
1314
import org.elasticsearch.action.fieldcaps.TransportFieldCapabilitiesAction;
1415
import org.elasticsearch.common.settings.Setting;
@@ -119,11 +120,15 @@ public void testTimeoutSetting() {
119120
var failure = failures.getFirst();
120121
assertThat(failure.getIndices().length, Matchers.is(1));
121122
assertThat(failure.getIndices()[0], Matchers.equalTo("cluster-a:*"));
123+
// Outer wrapper that gets unwrapped in ExceptionsHelper.isRemoteUnavailableException().
122124
assertThat(
123125
failure.getException().toString(),
124-
Matchers.containsString("org.elasticsearch.ElasticsearchTimeoutException: timed out after [1s/1000ms]")
126+
Matchers.containsString("java.lang.IllegalStateException: Unable to open any connections")
125127
);
126128

129+
// The actual error that is thrown by the subscribable listener when a remote could not be talked to.
130+
assertThat(failure.getException().getCause(), Matchers.instanceOf(ElasticsearchTimeoutException.class));
131+
127132
latch.countDown();
128133
result.decRef();
129134
}

server/src/main/java/org/elasticsearch/action/fieldcaps/TransportFieldCapabilitiesAction.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,11 @@ private static void mergeIndexResponses(
405405
* Under no circumstances are we to pass timeout errors originating from SubscribableListener as top-level errors.
406406
* Instead, they should always be passed through the response object, as part of "failures".
407407
*/
408-
if (failures.stream().anyMatch(failure -> failure.getException() instanceof ElasticsearchTimeoutException)) {
408+
if (failures.stream()
409+
.anyMatch(
410+
failure -> failure.getException() instanceof IllegalStateException ise
411+
&& ise.getCause() instanceof ElasticsearchTimeoutException
412+
)) {
409413
listener.onResponse(new FieldCapabilitiesResponse(Collections.emptyList(), failures));
410414
} else {
411415
// throw back the first exception
@@ -618,15 +622,24 @@ List<FieldCapabilitiesFailure> build(Set<String> successfulIndices) {
618622
for (Map.Entry<String, Exception> failure : failuresByIndex.entrySet()) {
619623
String index = failure.getKey();
620624
Exception e = failure.getValue();
625+
/*
626+
* The listener we use to briefly try, and connect to a remote can throw an ElasticsearchTimeoutException
627+
* error if a remote cannot be reached. To make sure we correctly recognise this scenario via
628+
* ExceptionsHelper.isRemoteUnavailableException(), we wrap this error appropriately.
629+
*/
630+
if (e instanceof ElasticsearchTimeoutException ete) {
631+
e = new IllegalStateException("Unable to open any connections", ete);
632+
}
621633

622634
if (successfulIndices.contains(index) == false) {
623635
// we deduplicate exceptions on the underlying causes message and classname
624636
// we unwrap the cause to e.g. group RemoteTransportExceptions coming from different nodes if the cause is the same
625637
Throwable cause = ExceptionsHelper.unwrapCause(e);
626638
Tuple<String, String> groupingKey = new Tuple<>(cause.getMessage(), cause.getClass().getName());
639+
Exception ex = e;
627640
indexFailures.compute(
628641
groupingKey,
629-
(k, v) -> v == null ? new FieldCapabilitiesFailure(new String[] { index }, e) : v.addIndex(index)
642+
(k, v) -> v == null ? new FieldCapabilitiesFailure(new String[] { index }, ex) : v.addIndex(index)
630643
);
631644
}
632645
}

0 commit comments

Comments
 (0)