{"record":{"id":"ebae931f876def07","repo":"hyperledger/fabric","slug":"error-discarding-d-bytes","errorCode":null,"errorMessage":"error discarding [%d] bytes","messagePattern":"error discarding \\[(.+?)\\] bytes","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/ledger/blkstorage/block_stream.go","lineNumber":125,"sourceCode":"\t}\n\tlength, n := protowire.ConsumeVarint(lenBytes)\n\tif n <= 0 {\n\t\t// proto.DecodeVarint did not consume any byte at all which means that the bytes\n\t\t// representing the size of the block are partial bytes\n\t\tif !moreContentAvailable {\n\t\t\treturn nil, nil, ErrUnexpectedEndOfBlockfile\n\t\t}\n\t\tpanic(errors.Errorf(\"Error in decoding varint bytes [%#v]\", lenBytes))\n\t}\n\tbytesExpected := int64(n) + int64(length)\n\tif bytesExpected > remainingBytes {\n\t\tlogger.Debugf(\"At least [%d] bytes expected. Remaining bytes = [%d]. Returning with error [%s]\",\n\t\t\tbytesExpected, remainingBytes, ErrUnexpectedEndOfBlockfile)\n\t\treturn nil, nil, ErrUnexpectedEndOfBlockfile\n\t}\n\t// skip the bytes representing the block size\n\tif _, err = s.reader.Discard(n); err != nil {\n\t\treturn nil, nil, errors.Wrapf(err, \"error discarding [%d] bytes\", n)\n\t}\n\tblockBytes := make([]byte, length)\n\tif _, err = io.ReadAtLeast(s.reader, blockBytes, int(length)); err != nil {\n\t\tlogger.Errorf(\"Error reading [%d] bytes from file number [%d], error: %s\", length, s.fileNum, err)\n\t\treturn nil, nil, errors.Wrapf(err, \"error reading [%d] bytes from file number [%d]\", length, s.fileNum)\n\t}\n\tblockPlacementInfo := &blockPlacementInfo{\n\t\tfileNum:          s.fileNum,\n\t\tblockStartOffset: s.currentOffset,\n\t\tblockBytesOffset: s.currentOffset + int64(n),\n\t}\n\ts.currentOffset += int64(n) + int64(length)\n\tlogger.Debugf(\"Returning blockbytes - length=[%d], placementInfo={%s}\", len(blockBytes), blockPlacementInfo)\n\treturn blockBytes, blockPlacementInfo, nil\n}\n\nfunc (s *blockfileStream) close() error {\n\treturn errors.WithStack(s.file.Close())","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/common/ledger/blkstorage/block_stream.go#L107-L143","documentation":"Wraps the bufio.Reader.Discard error when skipping the varint bytes representing the block size. Discard fails only on an I/O error or negative byte count, since the code has already verified via Peek that n bytes are buffered. This indicates a low-level read failure at the moment of consumption.","triggerScenarios":"nextBlockBytesAndPlacementInfo calls s.reader.Discard(n) after a successful Peek; failure means an underlying I/O error or an inconsistent buffer state (e.g. file changed between Peek and Discard).","commonSituations":"Disk I/O errors; file truncated/replaced between the Peek and Discard calls by an external process; descriptor issues on network-backed storage.","solutions":["Inspect the wrapped OS error and check storage health","Ensure nothing external truncates or replaces blockfiles while the peer reads them","Reopen the block stream and retry from the last known-good offset","If corruption is suspected, restore the file from backup or re-sync from peers"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"blk, err := stream.nextBlockBytes()\nif err != nil {\n    if isTransientIO(errors.Cause(err)) {\n        return reopenStreamAndRetry(offset)\n    }\n    return err\n}","preventionTips":["Avoid network filesystems for ledger data; use local disks","Keep the peer stopped during file maintenance","Monitor disk/controller errors in system logs"],"tags":["fabric","ledger","bufio","io"],"backgroundTag":"io-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"}