{"record":{"id":"30997c34682e8a5d","repo":"apache/druid","slug":"truncated-response-context","errorCode":"Truncated response context","errorMessage":"Serialized response context exceeds the max size[%s]","messagePattern":"Serialized response context exceeds the max size\\[(.+?)\\]","errorType":"http","errorClass":"QueryInterruptedException","httpStatus":500,"severity":"error","filePath":"server/src/main/java/org/apache/druid/server/QueryResultPusher.java","lineNumber":502,"sourceCode":"            jsonMapper,\n            responseContextConfig.getMaxResponseContextHeaderSize()\n        );\n      }\n      catch (JsonProcessingException e) {\n        log.info(e, \"Problem serializing to JSON!?\");\n        serializationResult = new ResponseContext.SerializationResult(\"Could not serialize\", \"Could not serialize\");\n      }\n\n      if (serializationResult.isTruncated()) {\n        final String logToPrint = StringUtils.format(\n            \"Response Context truncated for id [%s]. Full context is [%s].\",\n            queryId,\n            serializationResult.getFullResult()\n        );\n\n        if (responseContextConfig.shouldFailOnTruncatedResponseContext()) {\n          log.error(logToPrint);\n          throw new QueryInterruptedException(\n              new TruncatedResponseContextException(\n                  \"Serialized response context exceeds the max size[%s]\",\n                  responseContextConfig.getMaxResponseContextHeaderSize()\n              ),\n              selfNode.getHostAndPortToUse()\n          );\n        } else {\n          log.warn(logToPrint);\n        }\n      }\n      response.setHeader(QueryResource.HEADER_RESPONSE_CONTEXT, serializationResult.getResult());\n    }\n\n    @Override\n    @Nullable\n    public Response accumulate(Response retVal, Object in)\n    {\n      if (!initialized) {","sourceCodeStart":484,"sourceCodeEnd":520,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/server/src/main/java/org/apache/druid/server/QueryResultPusher.java#L484-L520","documentation":"When pushing results (QueryResultPusher), the serialized response context header is capped by druid.broker.http maxResponseContextHeaderSize. If the serialized context exceeds the limit and shouldFailOnTruncatedResponseContext is true, a QueryInterruptedException wrapping TruncatedResponseContextException is thrown instead of silently truncating.","triggerScenarios":"A query response context larger than maxResponseContextHeaderSize (e.g. many chained subqueries accumulating context keys, large cached/tag data in context) combined with shouldFailOnTruncatedResponseContext=true.","commonSituations":"Deeply nested SQL queries generating large response context payloads; clients stuffing large custom context values into native queries; strict-failure clusters with legacy big context headers.","solutions":["Increase druid.broker.http maxResponseContextHeaderSize (and maxResponseContextBufferSize)","Reduce context payload: remove large custom context values from queries","Set shouldFailOnTruncatedResponseContext=false to truncate instead of failing (with awareness that context may be lost)","Upgrade/flatten very deeply nested queries that inflate the context"],"exampleFix":"// before\nruntime.properties:\n  druid.broker.http.maxResponseContextHeaderSize=1000\n// after\n  druid.broker.http.maxResponseContextHeaderSize=8192","handlingStrategy":"validation","validationCode":"int serializedSize = ResponseContext.serializeSize(context);\nif (serializedSize > maxResponseContextHeaderSize) {\n  throw new IllegalArgumentException(\"Trim response context; \" + serializedSize\n      + \" exceeds \" + maxResponseContextHeaderSize);\n}","typeGuard":null,"tryCatchPattern":"try {\n  pusher.run();\n} catch (QueryInterruptedException e) {\n  if (e.getErrorCode().equals(\"Truncated response context\")) {\n    log.error(\"Response context too large; increase maxResponseContextHeaderSize or trim context\");\n  }\n  throw e;\n}","preventionTips":["Keep query context values small; never pass bulk data via context","Increase maxResponseContextHeaderSize for clusters running deep SQL/nested queries","Understand shouldFailOnTruncatedResponseContext before enabling it","Monitor context header sizes in high-fanout broker setups"],"tags":["query","http","response-context","limit"],"backgroundTag":"payload-too-large","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"}