[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>
This commit is contained in:
Ignacio Vera 2025-03-17 17:29:12 +01:00 committed by GitHub
parent 73fc040661
commit 0dec400ebc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 1 deletions

View file

@ -0,0 +1,5 @@
pr: 125002
summary: Don't generate stacktrace in `TaskCancelledException`
area: Search
type: bug
issues: []

View file

@ -42,6 +42,7 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcke
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
public class SearchCancellationIT extends AbstractSearchCancellationTestCase { public class SearchCancellationIT extends AbstractSearchCancellationTestCase {
@ -124,7 +125,9 @@ public class SearchCancellationIT extends AbstractSearchCancellationTestCase {
logger.info("All shards failed with", ex); logger.info("All shards failed with", ex);
if (lowLevelCancellation) { if (lowLevelCancellation) {
// Ensure that we cancelled in TimeSeriesIndexSearcher and not in reduce phase // Ensure that we cancelled in TimeSeriesIndexSearcher and not in reduce phase
assertThat(ExceptionsHelper.stackTrace(ex), containsString("TimeSeriesIndexSearcher")); assertThat(ExceptionsHelper.stackTrace(ex), not(containsString("not building sub-aggregations due to task cancellation")));
} else {
assertThat(ExceptionsHelper.stackTrace(ex), containsString("not building sub-aggregations due to task cancellation"));
} }
} }
} }

View file

@ -27,6 +27,11 @@ public class TaskCancelledException extends ElasticsearchException {
super(in); super(in);
} }
@Override
public Throwable fillInStackTrace() {
return this; // this exception doesn't imply a bug, no need for a stack trace
}
@Override @Override
public RestStatus status() { public RestStatus status() {
// Tasks are typically cancelled at the request of the client, so a 4xx status code is more accurate than the default of 500 (and // Tasks are typically cancelled at the request of the client, so a 4xx status code is more accurate than the default of 500 (and