{"record":{"id":"f0cce439c4787210","repo":"apache/hadoop","slug":"invalid-content-length-header-contentlength","errorCode":null,"errorMessage":"\"Invalid Content-Length header: \" + contentLength","messagePattern":"\"Invalid Content-Length header: \" \\+ contentLength","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EditLogFileInputStream.java","lineNumber":505,"sourceCode":"                connection = (HttpURLConnection)\n                    connectionFactory.openConnection(url, isSpnegoEnabled);\n              } catch (AuthenticationException e) {\n                throw new IOException(e);\n              }\n              \n              if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {\n                throw new HttpGetFailedException(\n                    \"Fetch of \" + url +\n                    \" failed with status code \" + connection.getResponseCode() +\n                    \"\\nResponse message:\\n\" + connection.getResponseMessage(),\n                    connection);\n              }\n        \n              String contentLength = connection.getHeaderField(CONTENT_LENGTH);\n              if (contentLength != null) {\n                advertisedSize = Long.parseLong(contentLength);\n                if (advertisedSize <= 0) {\n                  throw new IOException(\"Invalid \" + CONTENT_LENGTH + \" header: \" +\n                      contentLength);\n                }\n              } else {\n                throw new IOException(CONTENT_LENGTH + \" header is not provided \" +\n                                      \"by the server when trying to fetch \" + url);\n              }\n        \n              return connection.getInputStream();\n            }\n          });\n    }\n\n    @Override\n    public long length() {\n      return advertisedSize;\n    }\n\n    @Override","sourceCodeStart":487,"sourceCodeEnd":523,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EditLogFileInputStream.java#L487-L523","documentation":"IOException('Invalid Content-Length header') from EditLogFileInputStream.URLLog: the HTTP response for a remote edit log carried a Content-Length whose parsed value was <= 0. The fetcher requires a known positive length (it backs length() used for tail validation), so a non-positive value is treated as a protocol violation and the fetch aborts before reading the body.","triggerScenarios":"A proxy/LB in front of the NameNode rewriting the journal servlet response into a zero-length answer; a broken or half-failed GetImageServlet responding 200 with Content-Length: 0; malformed hand-built URLs hitting a different endpoint.","commonSituations":"JVM http proxy settings (http.proxyHost) routing NN traffic through a corporate proxy; LB health-check intercept; NN under extreme load closing early; version-skewed servlet between tailer and source.","solutions":["Bypass proxies for NN hosts: add the NN host to http.nonProxyHosts (or no_proxy) in the tailer's JVM env, or fix LB pass-through.","Verify the raw response by hand: curl -sv '<getedit URL>' --negotiate and inspect headers; a real 200 with a sane Content-Length points back at the intermediary.","If the source NN itself emits 0-length, check its logs for the servlet exception and upgrade/patch if it is a known servlet bug."],"exampleFix":"# before: JVM routes NN fetch via corporate proxy -> Content-Length: 0\nexport JAVA_TOOL_OPTIONS=-Dhttp.nonProxyHosts='nn1.example.com|nn2.example.com|localhost'\n# after: fetch goes direct, servlet's real Content-Length is honored","handlingStrategy":"try-catch","validationCode":"curl -sv --negotiate '<getedit URL>' -o /dev/null 2>&1 | grep -i content-length\n# a sane positive Content-Length from a direct fetch confirms an intermediary is mangling it","typeGuard":null,"tryCatchPattern":"catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"Invalid Content-Length\")) {\n    // do not retry blindly: fix proxy/LB in the path first, then retry once\n  } else { throw e; }\n}","preventionTips":["Exclude NameNode hosts from JVM/HTTP proxies (http.nonProxyHosts, no_proxy).","Health-check LB paths to journal servlets; ensure pass-through, not interception.","Smoke-test the getedit endpoint with curl after network topology changes."],"tags":["hdfs","edit-log","http","content-length","proxy"],"backgroundTag":"invalid-content-length","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}