{"record":{"id":"d6353045e25e27ad","repo":"apache/hadoop","slug":"content-length-header-is-not-provided-by-the-serv","errorCode":null,"errorMessage":"\"Content-Length header is not provided by the server when trying to fetch \" + url","messagePattern":"\"Content-Length header is not provided by the server when trying to fetch \" \\+ url","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":509,"sourceCode":"              }\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\n    public String getName() {\n      return url.toString();\n    }\n  }","sourceCodeStart":491,"sourceCodeEnd":527,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EditLogFileInputStream.java#L491-L527","documentation":"IOException from EditLogFileInputStream.URLLog when the HTTP response for a remote edit log has no Content-Length header at all. The edit-log fetcher must know the stream length up front (length() feeds tail-position math and integrity checks), so a response without the header -- typically transfer-encoding: chunked -- is rejected instead of read.","triggerScenarios":"An intermediary (proxy/LB) re-chunking the GetImageServlet response; a very old or nonconforming server; SSL-terminating frontends that drop the header. The tailer opens the URL, getHeaderField('Content-Length') returns null, and the fetch fails immediately.","commonSituations":"Corporate proxy or nginx/HAProxy between standby and active NN; direct curl shows 'Transfer-Encoding: chunked' where the NN itself would send Content-Length; JVM proxy env vars accidentally applying to NN traffic.","solutions":["Make the tailer talk directly to the NameNode: clear http.proxyHost for NN hosts (http.nonProxyHosts) or remove the LB from that path.","Confirm with curl -sv what the endpoint really returns; if the NN itself omits the header, check its version and upgrade.","Reconfigure the proxy/LB to buffer the response so the upstream Content-Length is preserved."],"exampleFix":"# before: standby -> nginx -> active, response arrives chunked with no Content-Length\ncurl -sv http://nginx:9870/getimage?getedit=1&txid=42 -o /dev/null   # shows Transfer-Encoding: chunked\n# after: point the tailer straight at the active NN\n# (set the shared-edits/tailing URL to http://nn-active:9870 or add it to no_proxy)","handlingStrategy":"try-catch","validationCode":"curl -sv --negotiate '<getedit URL>' -o /dev/null 2>&1 | egrep -i 'content-length|transfer-encoding'\n# 'Transfer-Encoding: chunked' where the NN would send Content-Length = intermediary re-chunking","typeGuard":null,"tryCatchPattern":"catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"header is not provided\")) {\n    // env/proxy issue, not data loss: remove the intermediary for this URL and retry\n  } else { throw e; }\n}","preventionTips":["Keep tailer-to-NameNode traffic direct; configure proxies/LBs to buffer so Content-Length survives.","After any network change, verify the journal endpoint's headers with curl.","Pin dfs.namenode.http-address to the real NN host, not a chunking VIP."],"tags":["hdfs","edit-log","http","content-length","proxy","chunked-encoding"],"backgroundTag":"missing-content-length-header","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}