{"record":{"id":"a752d8bb309e13f2","repo":"apache/druid","slug":"premature-eof","errorCode":null,"errorMessage":"Premature EOF","messagePattern":"Premature EOF","errorType":"exception","errorClass":"JsonMappingException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/context/ResponseContextDeserializer.java","lineNumber":112,"sourceCode":"      default:\n        if (token.isScalarValue()) {\n          return;\n        }\n        throw new JsonMappingException(jp, \"Invalid JSON inside unknown key: \" + key);\n    }\n  }\n\n  /**\n   * Freewheel over the contents of a structured object, including any\n   * nested structured objects, until the given end token.\n   */\n  private void skipTo(final JsonParser jp, JsonToken end) throws IOException\n  {\n    while (true) {\n      jp.nextToken();\n      final JsonToken token = jp.currentToken();\n      if (token == null) {\n        throw new JsonMappingException(jp, \"Premature EOF\");\n      }\n      switch (token) {\n        case START_OBJECT:\n          skipTo(jp, JsonToken.END_OBJECT);\n          break;\n        case START_ARRAY:\n          skipTo(jp, JsonToken.END_ARRAY);\n          break;\n        default:\n          if (token == end) {\n            return;\n          }\n      }\n    }\n  }\n}\n","sourceCodeStart":94,"sourceCodeEnd":129,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/context/ResponseContextDeserializer.java#L94-L129","documentation":"ResponseContextDeserializer.skipTo throws JsonMappingException(\"Premature EOF\") when the JSON parser returns a null token (end of input) before reaching the expected end token (END_OBJECT or END_ARRAY) while skipping an unknown key's structured value. The serialized response context is truncated or unbalanced.","triggerScenarios":"Deserializing a response context whose JSON is truncated — e.g. a header cut off by proxy limits, Base64 corruption, or a nested object/array that was never closed.","commonSituations":"HTTP header size limits truncating X-Druid-Response-Context on large contexts (many tasks/segments); intermediaries stripping or mangling headers; version-skewed serialization formats.","solutions":["Inspect/repair the source header — check for truncation at proxies or load balancers (max header size settings)","Reduce response-context size (fewer keys) or upgrade Druid versions that trim context contents","Regenerate the request/response; the context is a per-request value so retry with a fresh query","Catch JsonMappingException and fall back to an empty/default ResponseContext for the affected key"],"exampleFix":"// before\nString ctx = request.getHeader(\"X-Druid-Response-Context\"); // may be truncated\nResponseContext rc = mapper.readValue(ctx, ResponseContext.class);\n// after\ntry {\n  ResponseContext rc = mapper.readValue(ctx, ResponseContext.class);\n} catch (JsonMappingException e) {\n  log.warn(e, \"Bad response context header; ignoring\");\n}","handlingStrategy":"try-catch","validationCode":"// check balanced JSON before deserializing\ntry { mapper.readTree(headerValue); } catch (JsonProcessingException e) { /* header truncated/corrupt */ }","typeGuard":null,"tryCatchPattern":"try { rc = mapper.readValue(headerValue, ResponseContext.class); } catch (JsonMappingException e) { log.warn(e, \"Premature EOF in response context\"); rc = ResponseContext.createEmpty(); }","preventionTips":["Increase proxy/load-balancer max header size if contexts grow large","Minimize response-context keys emitted per query","Retry the query if the header appears truncated"],"tags":["jackson","json","eof","response-context"],"backgroundTag":"json-parse-error","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}