Skip to content

Commit aba54e8

Browse files
authored
Don't generate stacktrace in TaskCancelledException (#125002)
1 parent 0bacede commit aba54e8

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

docs/changelog/125002.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 125002
2+
summary: Don't generate stacktrace in `TaskCancelledException`
3+
area: Search
4+
type: bug
5+
issues: []

modules/aggregations/src/internalClusterTest/java/org/elasticsearch/aggregations/bucket/SearchCancellationIT.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
4444
import static org.hamcrest.Matchers.containsString;
4545
import static org.hamcrest.Matchers.equalTo;
46+
import static org.hamcrest.Matchers.not;
4647

4748
public class SearchCancellationIT extends AbstractSearchCancellationTestCase {
4849

@@ -97,9 +98,7 @@ public void testCancellationDuringTimeSeriesAggregation() throws Exception {
9798
}
9899

99100
logger.info("Executing search");
100-
// we have to explicitly set error_trace=true for the later exception check for `TimeSeriesIndexSearcher`
101101
Client client = client();
102-
client.threadPool().getThreadContext().putHeader("error_trace", "true");
103102
TimeSeriesAggregationBuilder timeSeriesAggregationBuilder = new TimeSeriesAggregationBuilder("test_agg");
104103
ActionFuture<SearchResponse> searchResponse = client.prepareSearch("test")
105104
.setQuery(matchAllQuery())
@@ -129,7 +128,9 @@ public void testCancellationDuringTimeSeriesAggregation() throws Exception {
129128
logger.info("All shards failed with", ex);
130129
if (lowLevelCancellation) {
131130
// Ensure that we cancelled in TimeSeriesIndexSearcher and not in reduce phase
132-
assertThat(ExceptionsHelper.stackTrace(ex), containsString("TimeSeriesIndexSearcher"));
131+
assertThat(ExceptionsHelper.stackTrace(ex), not(containsString("not building sub-aggregations due to task cancellation")));
132+
} else {
133+
assertThat(ExceptionsHelper.stackTrace(ex), containsString("not building sub-aggregations due to task cancellation"));
133134
}
134135
}
135136
}

server/src/main/java/org/elasticsearch/tasks/TaskCancelledException.java

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ public TaskCancelledException(StreamInput in) throws IOException {
2727
super(in);
2828
}
2929

30+
@Override
31+
public Throwable fillInStackTrace() {
32+
return this; // this exception doesn't imply a bug, no need for a stack trace
33+
}
34+
3035
@Override
3136
public RestStatus status() {
3237
// Tasks are typically cancelled at the request of the client, so a 4xx status code is more accurate than the default of 500 (and

0 commit comments

Comments
 (0)