{"record":{"id":"2f7ac98765ec57e5","repo":"apache/druid","slug":"query-s-timed-out-2f7ac9","errorCode":null,"errorMessage":"Query [%s] timed out","messagePattern":"Query \\[(.+?)\\] timed out","errorType":"exception","errorClass":"QueryTimeoutException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/scan/ScanQueryEngine.java","lineNumber":173,"sourceCode":"            final int batchSize = query.getBatchSize();\n            return new Iterator<>()\n            {\n              private long offset = 0;\n\n              @Override\n              public boolean hasNext()\n              {\n                return !cursor.isDone() && offset < limit;\n              }\n\n              @Override\n              public ScanResultValue next()\n              {\n                if (!hasNext()) {\n                  throw new NoSuchElementException();\n                }\n                if (hasTimeout && System.currentTimeMillis() >= timeoutAt) {\n                  throw new QueryTimeoutException(StringUtils.nonStrictFormat(\"Query [%s] timed out\", query.getId()));\n                }\n                final long lastOffset = offset;\n                final Object events;\n                final ScanQuery.ResultFormat resultFormat = query.getResultFormat();\n                if (ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST.equals(resultFormat)) {\n                  events = rowsToCompactedList();\n                } else if (ScanQuery.ResultFormat.RESULT_FORMAT_LIST.equals(resultFormat)) {\n                  events = rowsToList();\n                } else {\n                  throw new UOE(\"resultFormat[%s] is not supported\", resultFormat.toString());\n                }\n                responseContext.addRowScanCount(offset - lastOffset);\n                return new ScanResultValue(\n                    segment.getId() == null ? null : segment.getId().toString(),\n                    allColumns,\n                    events,\n                    rowSignatureBuilder.build()\n                );","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/scan/ScanQueryEngine.java#L155-L191","documentation":"The scan result iterator checks the query timeout on every next() call. When the current time reaches timeoutAt (derived from the query's timeout context), it throws QueryTimeoutException with the query id, aborting the scan. This enforces the 'timeout' query context parameter.","triggerScenarios":"Executing a scan query with a context timeout (hasTimeout true) whose execution exceeds the deadline; long scans over many segments with a small timeout value.","commonSituations":"Default low timeout in cluster config; large scans (millions of rows) exceeding client-set timeouts; slow disks or overloaded historicals making queries exceed the budget.","solutions":["Increase the 'timeout' value in the query context","Reduce scan scope: add filters, fewer columns, or lower limit/scanRows","Scale the historical tier or improve segment (column) caching","Catch QueryTimeoutException client-side and retry with a larger timeout"],"exampleFix":"// before\n{\"queryType\":\"scan\",\"context\":{\"timeout\":1000},...}\n// after\n{\"queryType\":\"scan\",\"context\":{\"timeout\":300000},...}","handlingStrategy":"try-catch","validationCode":"Long timeout = (Long) query.getContext().get(\"timeout\");\nif (timeout != null && timeout < expectedScanTimeMs) { /* raise or warn */ }","typeGuard":null,"tryCatchPattern":"try {\n  Sequence<ScanResultValue> seq = runner.run(QueryPlus.wrap(query), responseContext);\n  seq.toList();\n} catch (QueryTimeoutException e) {\n  // retry with larger timeout or narrow the query\n}","preventionTips":["Set realistic timeouts based on scan volume","Bound scans with limit/scanRows and filters","Monitor historical query latency and tune timeouts"],"tags":["druid","scan-query","timeout","query-context"],"backgroundTag":"request-timeout","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}