Don't generate stacktrace in TaskCancelledException (#125002)

This commit is contained in:
Ignacio Vera 2025-03-17 15:59:08 +01:00 committed by GitHub
parent 0bacede6cc
commit aba54e8af8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 3 deletions

View file

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

View file

@ -43,6 +43,7 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcke
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
public class SearchCancellationIT extends AbstractSearchCancellationTestCase {
@ -97,9 +98,7 @@ public class SearchCancellationIT extends AbstractSearchCancellationTestCase {
}
logger.info("Executing search");
// we have to explicitly set error_trace=true for the later exception check for `TimeSeriesIndexSearcher`
Client client = client();
client.threadPool().getThreadContext().putHeader("error_trace", "true");
TimeSeriesAggregationBuilder timeSeriesAggregationBuilder = new TimeSeriesAggregationBuilder("test_agg");
ActionFuture<SearchResponse> searchResponse = client.prepareSearch("test")
.setQuery(matchAllQuery())
@ -129,7 +128,9 @@ public class SearchCancellationIT extends AbstractSearchCancellationTestCase {
logger.info("All shards failed with", ex);
if (lowLevelCancellation) {
// 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);
}
@Override
public Throwable fillInStackTrace() {
return this; // this exception doesn't imply a bug, no need for a stack trace
}
@Override
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