apache/hadoop · error · IOException
"Invalid Content-Length header: " + contentLength
Error message
"Invalid Content-Length header: " + contentLength
What it means
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.
Source
Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EditLogFileInputStream.java:505
connection = (HttpURLConnection)
connectionFactory.openConnection(url, isSpnegoEnabled);
} catch (AuthenticationException e) {
throw new IOException(e);
}
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;
}
@OverrideView on GitHub (pinned to 2add963021)
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.
Example fix
# before: JVM routes NN fetch via corporate proxy -> Content-Length: 0 export JAVA_TOOL_OPTIONS=-Dhttp.nonProxyHosts='nn1.example.com|nn2.example.com|localhost' # after: fetch goes direct, servlet's real Content-Length is honored
Defensive patterns
Strategy: try-catch
Validate before calling
curl -sv --negotiate '<getedit URL>' -o /dev/null 2>&1 | grep -i content-length # a sane positive Content-Length from a direct fetch confirms an intermediary is mangling it
Try / catch
catch (IOException e) {
if (e.getMessage() != null && e.getMessage().contains("Invalid Content-Length")) {
// do not retry blindly: fix proxy/LB in the path first, then retry once
} else { throw e; }
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- "Content-Length header is not provided by the server when tr
- 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/f0cce439c4787210.
Report an issue: GitHub.