hyperledger/fabric · error
failed to create target folder for connection.json: %s
Error message
failed to create target folder for connection.json: %s
What it means
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.
Source
Thrown at ccaas_builder/cmd/release/main.go:76
connectionDestFile := filepath.Join(releaseDir, "chaincode/server/connection.json")
metadataDir := filepath.Join(builderOutputDir, "META-INF/statedb")
metadataDestDir := filepath.Join(releaseDir, "statedb")
if _, err := os.Stat(metadataDir); !os.IsNotExist(err) {
if err := copy.Copy(metadataDir, metadataDestDir); err != nil {
return fmt.Errorf("failed to copy metadataDir directory folder: %s", err)
}
}
// Process and update the connections file
_, err := os.Stat(connectionSrcFile)
if err != nil {
return fmt.Errorf("connection.json not found in source folder: %s", err)
}
err = os.MkdirAll(connectionDir, 0o750)
if err != nil {
return fmt.Errorf("failed to create target folder for connection.json: %s", err)
}
if err = Copy(connectionSrcFile, connectionDestFile); err != nil {
return err
}
return nil
}
// Copy the src file to dst. Any existing file will be overwritten and will not
// copy file attributes.
func Copy(src, dst string) error {
in, err := os.Open(src)
if err != nil {
return err
}
defer in.Close()
View on GitHub (pinned to 2736b63f8f)
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
Example fix
// before (core.yaml) maxRetries: 3 maxRetriesOnStartup: 10 // after maxRetries: 10 maxRetriesOnStartup: 20 internalQueryLimit: 1000 # smaller responses per request
Defensive patterns
Strategy: retry
Validate before calling
// pre-check reachability before large batch reads
resp, err := http.Get(couchURL + "/_up")
if err != nil || resp.StatusCode != 200 {
return errors.New("couchdb not healthy before batch read")
} Try / catch
if err != nil && strings.Contains(err.Error(), "error reading response body") {
// transient I/O failure — retry with backoff
return retry.Do(func() error { return batchRead(keys) }, retry.Attempts(maxRetries))
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- error reading multipart data
- too few arguments
- chaincode type not supported: %s
- incorrect number of arguments
- failed to copy metadataDir directory folder: %s
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/3990ae9634bebcd5.
Report an issue: GitHub.