Skip to content

Commit 6f33812

Browse files
authored
Avoid losing error message in failure collector (#111983)
The node-disconnected exception might not include the root cause. In this case, the failure collector incorrectly unwraps the exception and wraps it in a new Elasticsearch exception, losing the message. We should instead use the original exception to preserve the reason. Closes #111894
1 parent 19dc884 commit 6f33812

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

docs/changelog/111983.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 111983
2+
summary: Avoid losing error message in failure collector
3+
area: ES|QL
4+
type: bug
5+
issues:
6+
- 111894

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/FailureCollector.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,19 @@ public FailureCollector(int maxExceptions) {
4646
this.maxExceptions = maxExceptions;
4747
}
4848

49-
public void unwrapAndCollect(Exception originEx) {
50-
final Exception e = originEx instanceof TransportException
51-
? (originEx.getCause() instanceof Exception cause ? cause : new ElasticsearchException(originEx.getCause()))
52-
: originEx;
49+
private static Exception unwrapTransportException(TransportException te) {
50+
final Throwable cause = te.getCause();
51+
if (cause == null) {
52+
return te;
53+
} else if (cause instanceof Exception ex) {
54+
return ex;
55+
} else {
56+
return new ElasticsearchException(cause);
57+
}
58+
}
59+
60+
public void unwrapAndCollect(Exception e) {
61+
e = e instanceof TransportException te ? unwrapTransportException(te) : e;
5362
if (ExceptionsHelper.unwrap(e, TaskCancelledException.class) != null) {
5463
if (cancelledExceptionsCount.incrementAndGet() <= maxExceptions) {
5564
cancelledExceptions.add(e);

x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/FailureCollectorTests.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77

88
package org.elasticsearch.compute.operator;
99

10+
import org.elasticsearch.cluster.node.DiscoveryNodeUtils;
1011
import org.elasticsearch.common.Randomness;
1112
import org.elasticsearch.common.breaker.CircuitBreaker;
1213
import org.elasticsearch.common.breaker.CircuitBreakingException;
1314
import org.elasticsearch.tasks.TaskCancelledException;
1415
import org.elasticsearch.test.ESTestCase;
16+
import org.elasticsearch.transport.NodeDisconnectedException;
1517
import org.elasticsearch.transport.RemoteTransportException;
18+
import org.elasticsearch.transport.TransportException;
1619
import org.hamcrest.Matchers;
1720

1821
import java.io.IOException;
@@ -25,6 +28,9 @@
2528
import java.util.stream.IntStream;
2629
import java.util.stream.Stream;
2730

31+
import static org.hamcrest.Matchers.arrayWithSize;
32+
import static org.hamcrest.Matchers.equalTo;
33+
import static org.hamcrest.Matchers.instanceOf;
2834
import static org.hamcrest.Matchers.lessThan;
2935

3036
public class FailureCollectorTests extends ESTestCase {
@@ -87,4 +93,17 @@ public void testEmpty() {
8793
assertFalse(collector.hasFailure());
8894
assertNull(collector.getFailure());
8995
}
96+
97+
public void testTransportExceptions() {
98+
FailureCollector collector = new FailureCollector(5);
99+
collector.unwrapAndCollect(new NodeDisconnectedException(DiscoveryNodeUtils.builder("node-1").build(), "/field_caps"));
100+
collector.unwrapAndCollect(new TransportException(new CircuitBreakingException("too large", CircuitBreaker.Durability.TRANSIENT)));
101+
Exception failure = collector.getFailure();
102+
assertNotNull(failure);
103+
assertThat(failure, instanceOf(NodeDisconnectedException.class));
104+
assertThat(failure.getMessage(), equalTo("[][0.0.0.0:1][/field_caps] disconnected"));
105+
Throwable[] suppressed = failure.getSuppressed();
106+
assertThat(suppressed, arrayWithSize(1));
107+
assertThat(suppressed[0], instanceOf(CircuitBreakingException.class));
108+
}
90109
}

0 commit comments

Comments
 (0)