{"record":{"id":"e8d9be8e7981ab94","repo":"apache/druid","slug":"query-error-cancelling-pending-results-for-query","errorCode":null,"errorMessage":"Query error, cancelling pending results for query [%s]","messagePattern":"Query error, cancelling pending results for query \\[(.+?)\\]","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/ChainedExecutionQueryRunner.java","lineNumber":178,"sourceCode":"              return new MergeIterable<>(\n                  context.hasTimeout() ?\n                      future.get(context.getTimeout(), TimeUnit.MILLISECONDS) :\n                      future.get(),\n                  ordering.nullsFirst()\n              ).iterator();\n            }\n            catch (CancellationException | InterruptedException e) {\n              log.noStackTrace().warn(e, \"Query interrupted, cancelling pending results for query [%s]\", query.getId());\n              GuavaUtils.cancelAll(true, future, futures);\n              throw new QueryInterruptedException(e);\n            }\n            catch (TimeoutException | QueryTimeoutException e) {\n              log.noStackTrace().warn(e, \"Query timeout, cancelling pending results for query [%s]\", query.getId());\n              GuavaUtils.cancelAll(true, future, futures);\n              throw new QueryTimeoutException(StringUtils.nonStrictFormat(\"Query [%s] timed out\", query.getId()));\n            }\n            catch (ExecutionException e) {\n              log.noStackTrace().warn(e, \"Query error, cancelling pending results for query [%s]\", query.getId());\n              GuavaUtils.cancelAll(true, future, futures);\n              Throwable cause = e.getCause();\n              // Nested per-segment future timeout\n              if (cause instanceof TimeoutException) {\n                throw new QueryTimeoutException(StringUtils.nonStrictFormat(\"Query timeout, cancelling pending results for query [%s]. Per-segment timeout exceeded.\", query.getId()));\n              }\n              Throwables.throwIfUnchecked(cause);\n              throw new RuntimeException(cause);\n            }\n          }\n\n          @Override\n          public void cleanup(Iterator<T> tIterator)\n          {\n\n          }\n        }\n    );","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/ChainedExecutionQueryRunner.java#L160-L196","documentation":"ChainedExecutionQueryRunner.make() catches ExecutionException when a per-segment future fails, cancels all sibling futures, and logs 'Query error, cancelling pending results'. The cause is then re-thrown as the appropriate QueryInterruptedException/QueryTimeoutException or propagated as a query failure. This is the aggregate error path for any segment-level query failure.","triggerScenarios":"Any per-segment computation future completes exceptionally: segment loading errors, resource limit exceptions, query timeouts inside a segment, timeouts nested as TimeoutException causes, or data/node failures during the query.","commonSituations":"Historical node dies or times out mid-query; a segment fails to load (bad segment, missing local cache files); ResourceLimitExceededException from too many group-by/agg results; per-segment timeout (timeoutMs in query context) exceeded.","solutions":["Inspect the nested cause in the log and downstream broker response for the true segment error","If ResourceLimitExceededException, raise maxOnDiskStorage/maxMergingThreads or tune group-by buffers, or reduce query scope","If per-segment TimeoutException, increase the query context timeoutMs or prioritize the segment loading","Check historical node health/segment loading (coordinator logs, segment availability) if errors mention missing segments","Retry the query if the failure was due to a transient node restart or network blip"],"exampleFix":"// before\n{\"queryType\":\"groupBy\",\"...}\n// after: raise limits and timeout in context\n// {\"queryType\":\"groupBy\", ..., \"context\":{\"timeout\":300000,\"maxOnDiskStorage\":4000000000,\"groupBy.maxOnDiskStorage\":4000000000}}","handlingStrategy":"try-catch","validationCode":"// Check segment availability before querying\n// GET /druid/coordinator/v1/datasources/<ds>/segments is fully loaded\nboolean allLoaded = coordinatorSegments.stream()\n    .allMatch(s -> \"loaded\".equals(s.toLowerCase()));","typeGuard":null,"tryCatchPattern":"try {\n  result = queryClient.run(query);\n} catch (DruidException e) {\n  if (e.getErrorClass().contains(\"ResourceLimitExceeded\")) {\n    query = withRaisedLimits(query); // retry once with bigger buffers/timeout\n    result = queryClient.run(query);\n  } else {\n    throw e;\n  }\n}","preventionTips":["Monitor segment load state; failed/missing segments cause per-segment failures","Set realistic query context timeouts and group-by resource limits up front","Alert on historical node restarts, which surface as aggregate query errors","Read the nested cause — the runner cancels siblings and rethrows the root per-segment error"],"tags":["query-error","druid","segment-failure","distributed-query"],"backgroundTag":"database-query-failed","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}