{"record":{"id":"3990ae9634bebcd5","repo":"hyperledger/fabric","slug":"failed-to-create-target-folder-for-connection-json","errorCode":null,"errorMessage":"failed to create target folder for connection.json: %s","messagePattern":"failed to create target folder for connection\\.json: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ccaas_builder/cmd/release/main.go","lineNumber":76,"sourceCode":"\tconnectionDestFile := filepath.Join(releaseDir, \"chaincode/server/connection.json\")\n\n\tmetadataDir := filepath.Join(builderOutputDir, \"META-INF/statedb\")\n\tmetadataDestDir := filepath.Join(releaseDir, \"statedb\")\n\tif _, err := os.Stat(metadataDir); !os.IsNotExist(err) {\n\t\tif err := copy.Copy(metadataDir, metadataDestDir); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to copy metadataDir directory folder: %s\", err)\n\t\t}\n\t}\n\n\t// Process and update the connections file\n\t_, err := os.Stat(connectionSrcFile)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"connection.json not found in source folder: %s\", err)\n\t}\n\n\terr = os.MkdirAll(connectionDir, 0o750)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create target folder for connection.json: %s\", err)\n\t}\n\n\tif err = Copy(connectionSrcFile, connectionDestFile); err != nil {\n\t\treturn err\n\t}\n\n\treturn nil\n}\n\n// Copy the src file to dst. Any existing file will be overwritten and will not\n// copy file attributes.\nfunc Copy(src, dst string) error {\n\tin, err := os.Open(src)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer in.Close()\n","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/ccaas_builder/cmd/release/main.go#L58-L94","documentation":"After POSTing to CouchDB's _all_docs endpoint, the client reads the entire response body with io.ReadAll. If reading fails (connection reset mid-response, context cancellation, TLS termination), the error is wrapped as 'error reading response body' and the batch metadata retrieval fails.","triggerScenarios":"CouchDB (or an intermediary) closes the connection while the client is still reading the _all_docs response body; request context/timeout cancels mid-read; network interruption between peer and CouchDB during large batch reads.","commonSituations":"Firewall or LB with short idle timeouts killing long responses, CouchDB restarted under load during bulk reads, Kubernetes pod eviction of the CouchDB sidecar, TLS proxy misbehaving on large payloads.","solutions":["Retry the batch read — the wrapped request already supports MaxRetries; increase ledger.state.couchDBConfig.maxRetries and backoff","Check CouchDB/proxy logs for connection resets at the same timestamp","Raise proxy/firewall idle timeouts between peer and CouchDB","Reduce batch size or increase maxBatchUpdateSize-related limits to shrink response payload","Verify network stability (pod restarts, conntrack drops) between peer and CouchDB"],"exampleFix":"// before (core.yaml)\nmaxRetries: 3\nmaxRetriesOnStartup: 10\n// after\nmaxRetries: 10\nmaxRetriesOnStartup: 20\ninternalQueryLimit: 1000  # smaller responses per request","handlingStrategy":"retry","validationCode":"// pre-check reachability before large batch reads\nresp, err := http.Get(couchURL + \"/_up\")\nif err != nil || resp.StatusCode != 200 {\n    return errors.New(\"couchdb not healthy before batch read\")\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"error reading response body\") {\n    // transient I/O failure — retry with backoff\n    return retry.Do(func() error { return batchRead(keys) }, retry.Attempts(maxRetries))\n}","preventionTips":["Increase ledger.state.couchDBConfig.maxRetries and backoff for flaky networks","Raise LB/firewall idle timeouts between peer and CouchDB","Keep batches small so response bodies stay modest","Monitor CouchDB pod/container restarts under load","Use a stable direct network path, not an aggressive proxy"],"tags":["couchdb","network","io","fabric"],"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"}