moodle/moodle · error · HttpException
dechunk_fail
dechunk_fail
Error message
dechunk_fail
What it means
Internal error key used by phpxmlrpc's Http helper (Helper/Http.php, around line 224) when manual de-chunking of an HTTP response body fails. When the response was not handled by CURL, the helper re-implements transfer decoding itself; if the chunked-encoded body is malformed or truncated and cannot be de-chunked, the code sets/raises this 'dechunk_fail' error instead of returning garbage. It signals a corrupt HTTP response body received from the server.
Solutions
- Force HTTP/1.0 (curl option CURLOPT_HTTP_VERSION or equivalent transport option) to avoid chunked transfer encoding.
- Add 'Accept-Encoding' handling / ask server to send fixed-length content by disabling chunking server-side.
- Check intermediary proxies/CDNs that may truncate chunked bodies; bypass them to test.
- Retry the request — transient truncation may succeed on a second attempt.
Example fix
// before $client->setOption(CurlClient::OPT_CURL_HANDLE, ...); // default HTTP/1.1 // after $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); // avoid chunked $client->setOption(CurlClient::OPT_CURL_HANDLE, $ch);
Defensive patterns
Strategy: retry
Try / catch
try { $resp = $client->send($msg); } catch (\PhpXmlRpc\Exception\HttpException $e) { if ($e->getCode() === PhpXmlRpc::$xmlrpcerr['dechunk_fail']) { /* retry once, or force HTTP/1.0 */ } throw $e; } Prevention
- Avoid intermediaries known to break chunked responses.
- Use HTTP/1.0 or fixed-length responses where possible.
- Set sensible timeouts so bodies are not truncated mid-transfer.
When it happens
Trigger: HTTP/1.1 response with 'Transfer-Encoding: chunked' whose body ends prematurely (connection cut mid-transfer) or whose chunk-size lines are corrupted so static::decodeChunked() returns false.
Common situations: Proxy/load balancer mangling chunked responses, server or intermediary timing out mid-body, HTTP/1.1 keep-alive broken by firewalls, very large responses truncated.
Related errors
- Connecting to the content hub failed, please try again…
- http_error
- HTTP Error: for URI
- Calculated response checksum did not match the expected…
- Cannot determine HTTP method
AI-assisted analysis of moodle/moodle@48ea8c3322 (2026-09-14).
Data as JSON: /api/errors/12f90f23349ff5b2.
Report an issue: GitHub.
Appendix: source
Thrown at public/lib/phpxmlrpc/src/Helper/Http.php:224
if ($debug && count($httpResponse['headers'])) {
$msg = '';
foreach ($httpResponse['headers'] as $header => $value) {
$msg .= "HEADER: $header: $value\n";
}
foreach ($httpResponse['cookies'] as $header => $value) {
$msg .= "COOKIE: $header={$value['value']}\n";
}
$this->getLogger()->debug($msg);
}
// if CURL was used for the call, http headers have been processed, and dechunking + reinflating have been carried out
if (!$headersProcessed) {
// Decode chunked encoding sent by http 1.1 servers
if (isset($httpResponse['headers']['transfer-encoding']) && $httpResponse['headers']['transfer-encoding'] == 'chunked') {
if (!$data = static::decodeChunked($data)) {
$this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': errors occurred when trying to rebuild the chunked data received from server');
throw new HttpException(PhpXmlRpc::$xmlrpcstr['dechunk_fail'], PhpXmlRpc::$xmlrpcerr['dechunk_fail'], null, $httpResponse['status_code']);
}
}
// Decode gzip-compressed stuff
// code shamelessly inspired from nusoap library by Dietrich Ayala
if (isset($httpResponse['headers']['content-encoding'])) {
$httpResponse['headers']['content-encoding'] = str_replace('x-', '', $httpResponse['headers']['content-encoding']);
if ($httpResponse['headers']['content-encoding'] == 'deflate' || $httpResponse['headers']['content-encoding'] == 'gzip') {
// if decoding works, use it. else assume data wasn't gzencoded
if (function_exists('gzinflate')) {
if ($httpResponse['headers']['content-encoding'] == 'deflate' && $degzdata = @gzuncompress($data)) {
$data = $degzdata;
if ($debug) {
$this->getLogger()->debug("---INFLATED RESPONSE---[" . strlen($data) . " chars]---\n$data\n---END---");
}
} elseif ($httpResponse['headers']['content-encoding'] == 'gzip' && $degzdata = @gzinflate(substr($data, 10))) {
$data = $degzdata;
if ($debug) {View on GitHub (pinned to 48ea8c3322)