{"record":{"id":"a87a6987d515e5c5","repo":"hyperledger/fabric","slug":"invalid-response-received-from-couchdb","errorCode":null,"errorMessage":"invalid response received from CouchDB","messagePattern":"invalid response received from CouchDB","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdb.go","lineNumber":1170,"sourceCode":"\t}\n\n\tindexURL, err := url.Parse(dbclient.couchInstance.url())\n\tif err != nil {\n\t\tcouchdbLogger.Errorf(\"URL parse error: %s\", err)\n\t\treturn nil, errors.Wrapf(err, \"error parsing CouchDB URL: %s\", dbclient.couchInstance.url())\n\t}\n\n\t// get the number of retries\n\tmaxRetries := dbclient.couchInstance.conf.MaxRetries\n\n\tresp, _, err := dbclient.handleRequest(http.MethodPost, \"CreateIndex\", indexURL, []byte(indexdefinition), \"\", \"\", maxRetries, true, nil, \"_index\")\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer closeResponseBody(resp)\n\n\tif resp == nil {\n\t\treturn nil, errors.New(\"invalid response received from CouchDB\")\n\t}\n\n\t// Read the response body\n\trespBody, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"error reading response body\")\n\t}\n\n\tcouchDBReturn := &createIndexResponse{}\n\n\tjsonBytes := respBody\n\n\t// unmarshal the response\n\terr = json.Unmarshal(jsonBytes, &couchDBReturn)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"error unmarshalling json data\")\n\t}\n","sourceCodeStart":1152,"sourceCodeEnd":1188,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdb.go#L1152-L1188","documentation":"After handleRequest returns from the CreateIndex POST, the client checks that a non-nil *http.Response came back. A nil response with a nil error means the retry/existence-handling logic could not produce a usable response, so 'invalid response received from CouchDB' is returned. It guards against dereferencing a nil resp.","triggerScenarios":"Calling CreateIndex when handleRequest exhausts retries or short-circuits (e.g. index already exists handling path) and returns (nil, nil) instead of a live HTTP response.","commonSituations":"Repeated CreateIndex calls with the same design doc/name hitting the already-exists path; all connection attempts failing silently after MaxRetries; misconfigured retry settings combined with transient network failures.","solutions":["Check whether the index already exists (the rich API's IndexExists) before creating it again","Inspect handleRequest retry behavior: verify MaxRetries/connection settings in couchDBConfig","Confirm CouchDB reachability (curl host:5984/_up) so handleRequest returns a real response","Update Fabric if you rely on CreateIndex idempotency; newer versions surface the underlying error instead"],"exampleFix":"// before\nerr := indexDescription.CreateIndexIfNotExists()\n// after: pre-check existence\nexists, err := db.IsBulkMutable / indexExists(ddoc, name)\nif err == nil && !exists {\n    err = indexDescription.CreateIndexIfNotExists()\n}","handlingStrategy":"fallback","validationCode":"// pre-check to avoid the already-exists short-circuit path\n_, err := http.Get(fmt.Sprintf(\"http://%s/db/_index\", couchAddr))\n// or in chaincode use GetQueryResult with the index's fields to confirm usability","typeGuard":null,"tryCatchPattern":"err := idxDef.CreateIndexIfNotExists()\nif err != nil && strings.Contains(err.Error(), \"invalid response received from CouchDB\") {\n    // verify index existence another way instead of failing hard\n    return checkIndexUsableViaQuery()\n}","preventionTips":["Make index creation idempotent: fixed ddoc and name per index","Verify CouchDB reachability before peer startup","Upgrade Fabric if nil-response/nil-error returns are hit on new installs"],"tags":["couchdb","http","response","index"],"backgroundTag":"invalid-http-response","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"}