{"record":{"id":"e014c5d574ce027a","repo":"apache/druid","slug":"configured-timeout-d-is-more-than-enforced-limi","errorCode":null,"errorMessage":"Configured timeout = %d is more than enforced limit of %d.","messagePattern":"Configured timeout = (.+?) is more than enforced limit of (.+?)\\.","errorType":"validation","errorClass":"BadQueryContextException","httpStatus":400,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/QueryContext.java","lineNumber":545,"sourceCode":"  {\n    final long defaultTimeout = getLong(QueryContexts.DEFAULT_TIMEOUT_KEY, QueryContexts.DEFAULT_TIMEOUT_MILLIS);\n    if (defaultTimeout >= 0) {\n      return defaultTimeout;\n    }\n    throw new BadQueryContextException(\n        StringUtils.format(\n            \"Timeout [%s] must be a non negative value, but was %d\",\n            QueryContexts.DEFAULT_TIMEOUT_KEY,\n            defaultTimeout\n        )\n    );\n  }\n\n  public void verifyMaxQueryTimeout(long maxQueryTimeout)\n  {\n    long timeout = getTimeout();\n    if (timeout > maxQueryTimeout) {\n      throw new BadQueryContextException(\n          StringUtils.format(\n              \"Configured %s = %d is more than enforced limit of %d.\",\n              QueryContexts.TIMEOUT_KEY,\n              timeout,\n              maxQueryTimeout\n          )\n      );\n    }\n  }\n\n  public long getPerSegmentTimeout()\n  {\n    return getPerSegmentTimeout(QueryContexts.NO_TIMEOUT);\n  }\n\n  public long getPerSegmentTimeout(long defaultPerSegmentTimeout)\n  {\n    final long timeout = getLong(QueryContexts.PER_SEGMENT_TIMEOUT_KEY, defaultPerSegmentTimeout);","sourceCodeStart":527,"sourceCodeEnd":563,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/QueryContext.java#L527-L563","documentation":"Druid allows operators to enforce a maximum query timeout (maxQueryTimeout, e.g. via druid.query.scheduler or server config). QueryContext.verifyMaxQueryTimeout compares the effective `timeout` in the query context against that enforced limit and throws BadQueryContextException when the caller asks for more timeout than the server permits. This is a server-side resource-protection guard, not a type or format error.","triggerScenarios":"Calling QueryContext.verifyMaxQueryTimeout(long maxQueryTimeout) when the context's `timeout` value exceeds the enforced limit, e.g. context has `{\"timeout\": 600000}` (10 min) while the server enforces max 300000 ms (5 min).","commonSituations":"Clients migrating from an unenforced cluster to one with a max-query-timeout cap; dashboards with hard-coded long timeouts; operators lowering the enforced limit without notifying query clients.","solutions":["Lower the query's `timeout` context value to at or below the enforced limit reported in the message.","If the larger timeout is legitimate, have the operator raise the enforced maxQueryTimeout server-side.","Make clients discover the limit (config/endpoint) and clamp their requested timeout before submitting.","Catch BadQueryContextException and surface the 'enforced limit of %d' value to the user so they can adjust."],"exampleFix":"// before\ncontext.put(\"timeout\", 600_000L); // exceeds server limit of 300_000\n// after\nlong requested = 600_000L;\nlong limit = 300_000L; // obtained from server config\ncontext.put(\"timeout\", Math.min(requested, limit));","handlingStrategy":"validation","validationCode":"long requested = ((Number) query.getContext().getOrDefault(\"timeout\", 0L)).longValue();\nlong enforcedLimit = /* from broker config */ 300_000L;\nif (requested > enforcedLimit) {\n    query.getContext().put(\"timeout\", enforcedLimit);\n}","typeGuard":"boolean withinTimeoutLimit(Object v, long limit) {\n    return !(v instanceof Number) || ((Number) v).longValue() <= limit;\n}","tryCatchPattern":"try {\n    client.query(query);\n} catch (BadQueryContextException e) {\n    if (e.getMessage().contains(\"enforced limit of\")) {\n        long limit = parseEnforcedLimit(e.getMessage());\n        query.getContext().put(\"timeout\", limit);\n        client.query(query);\n    } else {\n        throw e;\n    }\n}","preventionTips":["Discover the server's enforced max timeout and clamp client requests to it.","Avoid hard-coding large timeouts in dashboards/tools; make them configurable.","Coordinate with operators when the enforced limit changes.","Prefer query optimization over raising timeout caps."],"tags":["query-context","timeout","limit","server-config"],"backgroundTag":"value-out-of-range","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"}