{"record":{"id":"61b28b512d29e9e6","repo":"hyperledger/fabric","slug":"couchdb-connection-error-expecting-return-code-of","errorCode":null,"errorMessage":"CouchDB connection error, expecting return code of 200, received %v","messagePattern":"CouchDB connection error, expecting return code of 200, received (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdbutil.go","lineNumber":94,"sourceCode":"\t\tDisableKeepAlives:     disableKeepAlive,\n\t}\n\n\tclient.Transport = transport\n\n\t// Create the CouchDB instance\n\tcouchInstance := &couchInstance{\n\t\tconf:   config,\n\t\tclient: client,\n\t\tstats:  newStats(metricsProvider),\n\t}\n\tconnectInfo, retVal, verifyErr := couchInstance.verifyCouchConfig()\n\tif verifyErr != nil {\n\t\treturn nil, verifyErr\n\t}\n\n\t// return an error if the http return value is not 200\n\tif retVal.StatusCode != http.StatusOK {\n\t\treturn nil, errors.Errorf(\"CouchDB connection error, expecting return code of 200, received %v\", retVal.StatusCode)\n\t}\n\n\t// check the CouchDB version number, return an error if the version is not at least 2.0.0\n\terrVersion := checkCouchDBVersion(connectInfo.Version)\n\tif errVersion != nil {\n\t\treturn nil, errVersion\n\t}\n\n\treturn couchInstance, nil\n}\n\nfunc checkCouchDBVersion(version string) error {\n\tcouchVersion := strings.Split(version, \".\")\n\tmajorVersion, _ := strconv.Atoi(couchVersion[0])\n\tminorVersion, _ := strconv.Atoi(couchVersion[1])\n\tif majorVersion < 2 {\n\t\treturn errors.Errorf(\"CouchDB v%s detected. CouchDB must be at least version 2.0.0\", version)\n\t}","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdbutil.go#L76-L112","documentation":"createCouchInstance verifies the CouchDB connection with an initial HTTP request; if the response status is not exactly 200 OK, it returns this error. It means the peer reached an HTTP server at the configured address but that server did not behave like a healthy CouchDB 2.x+ instance (or rejected the request).","triggerScenarios":"Calling CreateCouchInstance with connectInfo whose probe request (e.g. GET / with credentials) returns anything other than 200 — 401 unauthorized, 404 wrong path/proxy, 503 unavailable, or a non-CouchDB HTTP server answering.","commonSituations":"Wrong username/password in config; a reverse proxy or another service listening on the CouchDB port; CouchDB behind authentication that rejects the credentials; misconfigured port (e.g. pointing to the peer or another web service).","solutions":["Verify CouchDB address, port, username and password in the peer configuration (CORE_LEDGER_STATE_COUCHDBCONFIG_* env vars or core.yaml).","Confirm the server actually responds 200: curl -X GET http://admin:password@host:5984/ — it must return CouchDB JSON (db_name, version).","Check that no proxy/firewall intercepts the request and returns another status.","Ensure CouchDB is running and fully started (systemctl status / docker logs)."],"exampleFix":"// before (misconfigured)\nCORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=wronguser\n// after\nCORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=host:5984\nCORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=admin\nCORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=adminpass","handlingStrategy":"validation","validationCode":"const (\n  addr  = \"localhost:5984\"\n  user  = \"admin\"\n  pass  = \"adminpass\"\n)\nresp, _ := http.Get(\"http://\" + user + \":\" + pass + \"@\" + addr + \"/\")\n// must return 200 with JSON body containing \"couchdb\"","typeGuard":null,"tryCatchPattern":"couchInstance, err := couchdb.CreateCouchInstance(connectInfo, ...)\nif err != nil {\n    if strings.Contains(err.Error(), \"expecting return code of 200\") {\n        // check credentials, address, and that CouchDB (not a proxy) answers\n    }\n    return err\n}","preventionTips":["Smoke-test GET / on the CouchDB URL with curl before peer startup.","Point the config at CouchDB itself, not a proxy or another service.","Confirm CouchDB is fully started before launching the peer.","Keep credentials in env/config consistent with the CouchDB admin setup."],"tags":["couchdb","connection","http","configuration"],"backgroundTag":"connection-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"}