Skip to content

Commit 0dec400

Browse files
[8.17] Don't generate stacktrace in TaskCancelledException (#125002) (#125031)
* Don't generate stacktrace in TaskCancelledException (#125002) # Conflicts: # modules/aggregations/src/internalClusterTest/java/org/elasticsearch/aggregations/bucket/SearchCancellationIT.java * [CI] Auto commit changes from spotless --------- Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
1 parent 73fc040 commit 0dec400

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
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-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
4343
import static org.hamcrest.Matchers.containsString;
4444
import static org.hamcrest.Matchers.equalTo;
45+
import static org.hamcrest.Matchers.not;
4546

4647
public class SearchCancellationIT extends AbstractSearchCancellationTestCase {
4748

@@ -124,7 +125,9 @@ public void testCancellationDuringTimeSeriesAggregation() throws Exception {
124125
logger.info("All shards failed with", ex);
125126
if (lowLevelCancellation) {
126127
// Ensure that we cancelled in TimeSeriesIndexSearcher and not in reduce phase
127-
assertThat(ExceptionsHelper.stackTrace(ex), containsString("TimeSeriesIndexSearcher"));
128+
assertThat(ExceptionsHelper.stackTrace(ex), not(containsString("not building sub-aggregations due to task cancellation")));
129+
} else {
130+
assertThat(ExceptionsHelper.stackTrace(ex), containsString("not building sub-aggregations due to task cancellation"));
128131
}
129132
}
130133
}

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)