{"record":{"id":"d97f844f02d78469","repo":"hyperledger/fabric","slug":"error-reading-response-body","errorCode":null,"errorMessage":"error reading response body","messagePattern":"error reading response body","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdb.go","lineNumber":890,"sourceCode":"\tresp, _, err := dbclient.handleRequest(http.MethodGet, \"RangeDocRange\", rangeURL, nil, \"\", \"\", maxRetries, true, &queryParms, \"_all_docs\")\n\tif err != nil {\n\t\treturn nil, \"\", err\n\t}\n\tdefer closeResponseBody(resp)\n\n\tif couchdbLogger.IsEnabledFor(zapcore.DebugLevel) {\n\t\tdump, err2 := httputil.DumpResponse(resp, false)\n\t\tif err2 != nil {\n\t\t\tlog.Fatal(err2)\n\t\t}\n\t\t// compact debug log by replacing carriage return / line feed with dashes to separate http headers\n\t\tcouchdbLogger.Debugf(\"[%s] HTTP Response: %s\", dbclient.dbName, bytes.Replace(dump, []byte{0x0d, 0x0a}, []byte{0x20, 0x7c, 0x20}, -1))\n\t}\n\n\t// handle as JSON document\n\tjsonResponseRaw, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn nil, \"\", errors.Wrap(err, \"error reading response body\")\n\t}\n\n\tjsonResponse := &rangeQueryResponse{}\n\terr2 := json.Unmarshal(jsonResponseRaw, &jsonResponse)\n\tif err2 != nil {\n\t\treturn nil, \"\", errors.Wrap(err2, \"error unmarshalling json data\")\n\t}\n\n\t// if an additional record is found, then reduce the count by 1\n\t// and populate the nextStartKey\n\tif jsonResponse.TotalRows > limit {\n\t\tjsonResponse.TotalRows = limit\n\t}\n\n\tcouchdbLogger.Debugf(\"[%s] Total Rows: %d\", dbclient.dbName, jsonResponse.TotalRows)\n\n\t// Use the next endKey as the starting default for the nextStartKey\n\tnextStartKey := endKey","sourceCodeStart":872,"sourceCodeEnd":908,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdb.go#L872-L908","documentation":"Returned when io.ReadAll(resp.Body) fails while consuming the HTTP response from a CouchDB range query. The library received an HTTP response but could not read the body stream off the wire (connection dropped mid-response, timeout, or transport reset). The raw io error is wrapped with this fixed message.","triggerScenarios":"During handleRangeQuery: the _all_docs (or _design/...) GET returns headers successfully, then the TCP connection breaks or times out while streaming the JSON body.","commonSituations":"CouchDB container restarted or OOM-killed mid-request, load balancer idle-timeout closing long responses, network flakiness between peer and CouchDB, or very large range scans over slow links.","solutions":["Retry the range query; the error is usually transient network/transport failure.","Check CouchDB server health/logs around the failure time for crashes or restarts.","Reduce result-set size by narrowing the startKey/endKey or lowering limit to shorten the response window.","Inspect network path (proxies, LB idle timeouts) between peer and CouchDB and raise timeout limits."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if err := couchHealthCheck(client); err != nil {\n    return fmt.Errorf(\"couchdb unreachable before range scan: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"results, err := db.RangeScan(startKey, endKey)\nif err != nil && strings.Contains(err.Error(), \"error reading response body\") {\n    results, err = retryWithBackoff(3, func() ([]*queryResult, string, error) {\n        return db.RangeScan(startKey, endKey)\n    })\n}","preventionTips":["Monitor CouchDB health (/_up) and restart-on-failure in orchestration","Size range scans modestly; avoid huge single responses","Remove idle-timeout proxies between peer and CouchDB or raise their limits","Ensure stable networking (no aggressive conntrack/NAT drops) between peer and DB"],"tags":["couchdb","network","http-response"],"backgroundTag":"response-body-read-failed","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}