{"record":{"id":"7eb7ec7d1c959ee6","repo":"hyperledger/fabric","slug":"reading-http-response-body-s","errorCode":null,"errorMessage":"reading http response body: %s","messagePattern":"reading http response body: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/osnadmin/main.go","lineNumber":199,"sourceCode":"\t}\n\tif len(responseBody) != 0 {\n\t\tif statusCode == http.StatusOK && outputFile != \"\" {\n\t\t\tif err := os.WriteFile(outputFile, responseBody, 0o644); err != nil {\n\t\t\t\treturn \"\", err\n\t\t\t}\n\t\t} else {\n\t\t\tif err := json.Indent(&buffer, responseBody, \"\", \"\\t\"); err != nil {\n\t\t\t\treturn \"\", err\n\t\t\t}\n\t\t}\n\t}\n\treturn buffer.String(), nil\n}\n\nfunc readBodyBytes(body io.ReadCloser) ([]byte, error) {\n\tbodyBytes, err := io.ReadAll(body)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"reading http response body: %s\", err)\n\t}\n\tbody.Close()\n\n\treturn bodyBytes, nil\n}\n\nfunc errorOutput(err error) string {\n\treturn fmt.Sprintf(\"Error: %s\\n\", err)\n}\n\nfunc validateBlockChannelID(blockBytes []byte, channelID string) error {\n\tblock := &common.Block{}\n\terr := proto.Unmarshal(blockBytes, block)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unmarshalling block: %s\", err)\n\t}\n\n\tblockChannelID, err := protoutil.GetChannelIDFromBlock(block)","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/cmd/osnadmin/main.go#L181-L217","documentation":"readBodyBytes wraps errors from io.ReadAll on the HTTP response body returned by the orderer's osnadmin endpoints. If the connection is interrupted mid-response or the body stream errors, the CLI reports this message with the underlying cause.","triggerScenarios":"The orderer closes or resets the connection while the response body is being read; TLS handshake time-shift issues; proxy or load balancer truncating the response.","commonSituations":"Unstable network between CLI and orderer, orderer crash mid-request, timeouts or intermediaries terminating long-running HTTP responses.","solutions":["Retry the osnadmin command; the error is often transient.","Check orderer logs for a crash or connection reset.","Verify network connectivity and any proxy/LB between CLI and orderer.","Confirm the orderer is healthy and serving the admin port."],"exampleFix":"// before\nresp, err := osnadmin.Fetch(osnURL, ...) // connection drops mid-body\n// after\n// retry the command and verify orderer health\nresp, err := osnadmin.Fetch(osnURL, ...) // on stable connection","handlingStrategy":"retry","validationCode":"conn, err := net.DialTimeout(\"tcp\", \"orderer:9443\", 5*time.Second)\nif err != nil {\n    return fmt.Errorf(\"orderer unreachable before fetch: %w\", err)\n}\nconn.Close()","typeGuard":null,"tryCatchPattern":"for i := 0; i < 3; i++ {\n    resp, err := runOsnadminFetch()\n    if err == nil { break }\n    if strings.Contains(err.Error(), \"reading http response body:\") {\n        time.Sleep(2*time.Second); continue\n    }\n    return err\n}","preventionTips":["Check orderer health before issuing commands.","Avoid running admin operations over unstable links or aggressive LB timeouts.","Increase --tlsHandshakeTimeShift if clock skew causes issues.","Monitor orderer logs for connection resets."],"tags":["http","network","hyperledger-fabric"],"backgroundTag":"http-response-read-error","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"}