apache/hadoop · error · IOException
"Content-Length header is not provided by the server when tr
Error message
"Content-Length header is not provided by the server when trying to fetch " + url
What it means
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.
Source
Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EditLogFileInputStream.java:509
}
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
throw new HttpGetFailedException(
"Fetch of " + url +
" failed with status code " + connection.getResponseCode() +
"\nResponse message:\n" + connection.getResponseMessage(),
connection);
}
String contentLength = connection.getHeaderField(CONTENT_LENGTH);
if (contentLength != null) {
advertisedSize = Long.parseLong(contentLength);
if (advertisedSize <= 0) {
throw new IOException("Invalid " + CONTENT_LENGTH + " header: " +
contentLength);
}
} else {
throw new IOException(CONTENT_LENGTH + " header is not provided " +
"by the server when trying to fetch " + url);
}
return connection.getInputStream();
}
});
}
@Override
public long length() {
return advertisedSize;
}
@Override
public String getName() {
return url.toString();
}
}View on GitHub (pinned to 2add963021)
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.
Example fix
# before: standby -> nginx -> active, response arrives chunked with no Content-Length curl -sv http://nginx:9870/getimage?getedit=1&txid=42 -o /dev/null # shows Transfer-Encoding: chunked # after: point the tailer straight at the active NN # (set the shared-edits/tailing URL to http://nn-active:9870 or add it to no_proxy)
Defensive patterns
Strategy: try-catch
Validate before calling
curl -sv --negotiate '<getedit URL>' -o /dev/null 2>&1 | egrep -i 'content-length|transfer-encoding' # 'Transfer-Encoding: chunked' where the NN would send Content-Length = intermediary re-chunking
Try / catch
catch (IOException e) {
if (e.getMessage() != null && e.getMessage().contains("header is not provided")) {
// env/proxy issue, not data loss: remove the intermediary for this URL and retry
} else { throw e; }
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- "Invalid Content-Length header: " + contentLength
- Fetch of url failed with status code connection.getResponseC
- Content-Length is missing: ${headers}
- '%s' did not handle the '%s' delegation token operation: %s
- '%s' did not respond with JSON to the '%s' delegation token
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/d6353045e25e27ad.
Report an issue: GitHub.