{"record":{"id":"3a6440f0ab2fead1","repo":"elastic/elasticsearch","slug":"cancelled","errorCode":null,"errorMessage":"cancelled","messagePattern":"cancelled","errorType":"exception","errorClass":"TaskCancelledException","httpStatus":null,"severity":"warning","filePath":"modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/histogram/AutoDateHistogramAggregator.java","lineNumber":587,"sourceCode":"            return newRounding;\n        }\n\n        private void rebucket() {\n            rebucketCount++;\n            LongKeyedBucketOrds oldOrds = bucketOrds;\n            boolean success = false;\n            try {\n                long[] mergeMap = new long[Math.toIntExact(oldOrds.size())];\n                bucketOrds = new LongKeyedBucketOrds.FromMany(bigArrays());\n                success = true;\n                long maxOwning = oldOrds.maxOwningBucketOrd();\n                for (long owningBucketOrd = 0; owningBucketOrd <= maxOwning; owningBucketOrd++) {\n                    /*\n                     * Check for cancelation during this tight loop as it can take a while and the standard\n                     * cancelation checks don't run during the loop. Becuase it's a tight loop.\n                     */\n                    if (context.isCancelled()) {\n                        throw new TaskCancelledException(\"cancelled\");\n                    }\n                    LongKeyedBucketOrds.BucketOrdsEnum ordsEnum = oldOrds.ordsEnum(owningBucketOrd);\n                    Rounding.Prepared preparedRounding = preparedRoundings[roundingIndexFor(owningBucketOrd)];\n                    while (ordsEnum.next()) {\n                        long oldKey = ordsEnum.value();\n                        long newKey = preparedRounding.round(oldKey);\n                        long newBucketOrd = bucketOrds.add(owningBucketOrd, newKey);\n                        mergeMap[(int) ordsEnum.ord()] = newBucketOrd >= 0 ? newBucketOrd : -1 - newBucketOrd;\n                    }\n                    liveBucketCountUnderestimate = bigArrays().grow(liveBucketCountUnderestimate, owningBucketOrd + 1);\n                    liveBucketCountUnderestimate.set(owningBucketOrd, Math.toIntExact(bucketOrds.bucketsInOrd(owningBucketOrd)));\n                }\n                merge(mergeMap, bucketOrds.size());\n            } finally {\n                if (success) {\n                    oldOrds.close();\n                }\n            }","sourceCodeStart":569,"sourceCodeEnd":605,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/histogram/AutoDateHistogramAggregator.java#L569-L605","documentation":"Thrown as a TaskCancelledException inside AutoDateHistogramAggregator's bucket-remapping tight loop when AggregationContext.isCancelled() returns true. The auto_date_histogram re-rounds buckets in a long-running inner loop that bypasses the standard per-document cancellation checks, so it polls cancellation explicitly. This is normal operational behavior, not a bug — it propagates task cancellation (client cancel, timeout, node drop).","triggerScenarios":"A search containing an auto_date_histogram aggregation whose task is cancelled while it is in the re-rounding phase. Triggered by: client task cancellation API, search timeout (search.terminate_after / timeouts), shard relocation/failure, or node-level search cancellation.","commonSituations":"Long-running auto_date_histogram queries over large time ranges cancelled by users. Dashboards with auto-refresh where the user navigates away. Timeouts configured on the search. Heavy aggregation workload where the task manager reaps long tasks.","solutions":["Treat this as expected: catch TaskCancelledException in task-aware code and report the search as cancelled, not failed.","Reduce the workload (narrow time range, lower bucket count) so re-rounding completes within the cancellation window.","If cancellations are unexpected, investigate why the task was cancelled (client disconnects, timeouts, resource pressure).","Do not retry automatically without addressing the underlying cost — the cancellation was likely intentional."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { /* execute search with auto_date_histogram */ }\ncatch (org.elasticsearch.tasks.TaskCancelledException e) {\n  // report as cancelled, not failed; do not blind-retry\n}","preventionTips":["Treat TaskCancelledException as expected for long aggregations.","Size aggregations to complete within typical cancellation windows.","Investigate unexpected cancellations (timeouts, disconnects) before retrying."],"tags":["aggregations","auto-date-histogram","cancellation","task","operational"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}