hyperledger/fabric · error
error creating http request
Error message
error creating http request
What it means
Returned by handleRequest when http.NewRequestWithContext fails to construct the outgoing HTTP request for the CouchDB operation. This indicates an invalid method, malformed URL, or unusable request body (e.g. nil/invalid reader), not a network failure.
Source
Thrown at core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdb.go:1595
couchdbLogger.Debugf("Request URL: %s", requestURL)
// attempt the http request for the max number of retries
// if maxRetries is 0, the database creation will be attempted once and will
// return an error if unsuccessful
// if maxRetries is 3 (default), a maximum of 4 attempts (one attempt with 3 retries)
// will be made with warning entries for unsuccessful attempts
for attempts := 0; attempts <= maxRetries; attempts++ {
// Set up a buffer for the payload data
payloadData := new(bytes.Buffer)
payloadData.ReadFrom(bytes.NewReader(data))
// Create request based on URL for couchdb operation
req, err := http.NewRequestWithContext(ctx, method, requestURL.String(), payloadData)
if err != nil {
return nil, nil, errors.Wrap(err, "error creating http request")
}
// set the request to close on completion if shared connections are not allowSharedConnection
// Current CouchDB has a problem with zero length attachments, do not allow the connection to be reused.
// Apache JIRA item for CouchDB https://issues.apache.org/jira/browse/COUCHDB-3394
if !keepConnectionOpen {
req.Close = true
}
// add content header for PUT
if method == http.MethodPut || method == http.MethodPost || method == http.MethodDelete {
// If the multipartBoundary is not set, then this is a JSON and content-type should be set
// to application/json. Else, this is contains an attachment and needs to be multipart
if multipartBoundary == "" {
req.Header.Set("Content-Type", "application/json")
} else {
req.Header.Set("Content-Type", "multipart/related;boundary=\""+multipartBoundary+"\"")View on GitHub (pinned to 2736b63f8f)
Solutions
- Validate the CouchDB URL in config for illegal characters
- Ensure database names are lowercase alphanumeric (no uppercase/spaces), matching CouchDB naming rules
- Check any dynamically built path elements (doc IDs, attachment names) for unescaped characters
- Log the full requestURL.String() to identify the malformed part
Example fix
// before dbName := "Ledger1" // after dbName := strings.ToLower(dbName)
Defensive patterns
Strategy: validation
Validate before calling
if _, err := url.Parse(couchAddress); err != nil {
return fmt.Errorf("invalid couchdb address %q: %w", couchAddress, err)
}
if dbName != strings.ToLower(dbName) { return errors.New("dbname must be lowercase") } Prevention
- Enforce CouchDB lowercase database naming rules in creation code
- URL-escape document IDs and attachment names
- Validate configured CouchDB URL parses before opening the ledger
When it happens
Trigger: Calling handleRequest with a malformed requestURL (bad characters, unparseable URL), an invalid HTTP method string, or a broken payload reader when attaching large documents/attachments.
Common situations: Database or document names containing characters that break URL construction; database names with uppercase letters or invalid characters reaching constructCouchDBUrl; misconfigured CouchDB address with invalid characters.
Related errors
- chaincode type not supported: %s
- failed to copy metadataDir directory folder: %s
- error unmarshalling YAML file %s: %s
- error reading next multipart
- JSON format is not valid
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/37e36ef34cd9a584.
Report an issue: GitHub.