Skip to content

Commit ce8ec3f

Browse files
committed
Don't generate stacktrace in TaskCancelledException (elastic#125002)
# Conflicts: # modules/aggregations/src/internalClusterTest/java/org/elasticsearch/aggregations/bucket/SearchCancellationIT.java
1 parent e23159f commit ce8ec3f

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

docs/changelog/125002.yaml

Lines changed: 5 additions & 0 deletions
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

Lines changed: 6 additions & 3 deletions
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

@@ -101,8 +102,8 @@ public void testCancellationDuringTimeSeriesAggregation() throws Exception {
101102
.addAggregation(
102103
timeSeriesAggregationBuilder.subAggregation(
103104
new ScriptedMetricAggregationBuilder("sub_agg").initScript(
104-
new Script(ScriptType.INLINE, "mockscript", ScriptedBlockPlugin.INIT_SCRIPT_NAME, Collections.emptyMap())
105-
)
105+
new Script(ScriptType.INLINE, "mockscript", ScriptedBlockPlugin.INIT_SCRIPT_NAME, Collections.emptyMap())
106+
)
106107
.mapScript(
107108
new Script(ScriptType.INLINE, "mockscript", ScriptedBlockPlugin.MAP_BLOCK_SCRIPT_NAME, Collections.emptyMap())
108109
)
@@ -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

Lines changed: 5 additions & 0 deletions
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)