{"record":{"id":"997a555b3274385a","repo":"hyperledger/fabric","slug":"error-retrieving-file-info-for-file-number-d","errorCode":null,"errorMessage":"error retrieving file info for file number %d","messagePattern":"error retrieving file info for file number (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"common/ledger/blkstorage/blockfile_helper.go","lineNumber":168,"sourceCode":"\t\t\treturn -1, err\n\t\t}\n\t\tif fileNum > biggestFileNum {\n\t\t\tbiggestFileNum = fileNum\n\t\t}\n\t}\n\tlogger.Debugf(\"retrieveLastFileSuffix() - biggestFileNum = %d\", biggestFileNum)\n\treturn biggestFileNum, err\n}\n\nfunc isBlockFileName(name string) bool {\n\treturn strings.HasPrefix(name, blockfilePrefix)\n}\n\nfunc getFileInfoOrPanic(rootDir string, fileNum int) os.FileInfo {\n\tfilePath := deriveBlockfilePath(rootDir, fileNum)\n\tfileInfo, err := os.Lstat(filePath)\n\tif err != nil {\n\t\tpanic(errors.Wrapf(err, \"error retrieving file info for file number %d\", fileNum))\n\t}\n\treturn fileInfo\n}\n\nfunc loadBootstrappingSnapshotInfo(rootDir string) (*BootstrappingSnapshotInfo, error) {\n\tbsiBytes, err := os.ReadFile(filepath.Join(rootDir, bootstrappingSnapshotInfoFile))\n\tif os.IsNotExist(err) {\n\t\treturn nil, nil\n\t}\n\tif err != nil {\n\t\treturn nil, errors.Wrapf(err, \"error while reading bootstrappingSnapshotInfo file\")\n\t}\n\tbsi := &BootstrappingSnapshotInfo{}\n\tif err := proto.Unmarshal(bsiBytes, bsi); err != nil {\n\t\treturn nil, errors.Wrapf(err, \"error while unmarshalling bootstrappingSnapshotInfo\")\n\t}\n\treturn bsi, nil\n}","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/common/ledger/blkstorage/blockfile_helper.go#L150-L186","documentation":"This is a fatal panic raised by getFileInfoOrPanic when os.Lstat fails to stat a block file (e.g. blockfile_000000) in the ledger's block storage directory. It means the file on disk is missing or unreadable even though the manager expected it to exist (typically referenced by blockfilesInfo or a fs scan). constructBlockfilesInfo/syncBlockfilesInfoFromFS call it while scanning the chains dir.","triggerScenarios":"os.Lstat returns any error (permission denied, I/O error, race deletion) on a derived block file path during blockfilesInfo construction/sync; a block file referenced by the DB is missing from the filesystem.","commonSituations":"Files deleted manually or by cleanup scripts while the ledger exists in the index DB; permissions changed on /var/hyperledger/production; NFS mount issues; running peer as wrong user after restore from backup.","solutions":["Restore the missing block file from backup (or a snapshot) so Lstat succeeds","Check file permissions/ownership of the ledger's block storage dir and correct them (chown/chmod)","If the ledger data is disposable, remove the ledger dir (and index DB) so it is re-created on peer start","Verify the filesystem is healthy/mounted (dmesg, df) if Lstat fails with I/O errors"],"exampleFix":"// before: blindly trusting the DB's latestFileNumber after a partial copy\n// after: sync DB info from FS before opening, or restore files:\n// rsync -a backup/ledgersData/chains/mychannel/ /var/hyperledger/production/ledgersData/chains/mychannel/","handlingStrategy":"validation","validationCode":"// before peer start / external checks\nfilePath := filepath.Join(rootDir, fmt.Sprintf(\"blockfile_%06d\", fileNum))\nif _, err := os.Lstat(filePath); err != nil {\n    return fmt.Errorf(\"block file %s missing or unreadable: %w\", filePath, err)\n}","typeGuard":"func blockFileExists(rootDir string, fileNum int) bool {\n    _, err := os.Lstat(deriveBlockfilePath(rootDir, fileNum))\n    return err == nil\n}","tryCatchPattern":"// Go: the library panics; recover at manager-construction boundary\nfunc safeNewBlockStore(...) (s *BlockStore, err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"blockstore init failed: %v\", r)\n        }\n    }()\n    return newBlockStore(...)\n}","preventionTips":["Keep index DB and chains dirs in sync — always restore both from the same backup","Never delete or move block files while a peer is running","Ensure the peer user owns ledgersData recursively","Monitor disk/mount health on the ledger volume"],"tags":["filesystem","ledger-storage","panic"],"backgroundTag":"file-not-found","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"}