{"record":{"id":"6084b8f585a500cb","repo":"hyperledger/fabric","slug":"error-in-block-index-s","errorCode":null,"errorMessage":"error in block index: %s","messagePattern":"error in block index: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"common/ledger/blkstorage/blockfile_mgr.go","lineNumber":132,"sourceCode":"\t} else {\n\t\tlogger.Debug(`Syncing block information from block storage (if needed)`)\n\t\tsyncBlockfilesInfoFromFS(rootDir, blockfilesInfo)\n\t}\n\terr = mgr.saveBlkfilesInfo(blockfilesInfo, true)\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"Could not save next block file info to db: %s\", err))\n\t}\n\n\tcurrentFileWriter, err := newBlockfileWriter(deriveBlockfilePath(rootDir, blockfilesInfo.latestFileNumber))\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"Could not open writer to current file: %s\", err))\n\t}\n\terr = currentFileWriter.truncateFile(blockfilesInfo.latestFileSize)\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"Could not truncate current file to known size in db: %s\", err))\n\t}\n\tif mgr.index, err = newBlockIndex(indexConfig, indexStore); err != nil {\n\t\tpanic(fmt.Sprintf(\"error in block index: %s\", err))\n\t}\n\n\tmgr.blockfilesInfo = blockfilesInfo\n\tbsi, err := loadBootstrappingSnapshotInfo(rootDir)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tmgr.bootstrappingSnapshotInfo = bsi\n\tmgr.currentFileWriter = currentFileWriter\n\tmgr.blkfilesInfoCond = sync.NewCond(&sync.Mutex{})\n\n\tif err := mgr.syncIndex(); err != nil {\n\t\treturn nil, err\n\t}\n\n\tbcInfo := &common.BlockchainInfo{}\n\n\tif mgr.bootstrappingSnapshotInfo != nil {","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/common/ledger/blkstorage/blockfile_mgr.go#L114-L150","documentation":"This panic occurs in newBlockfileMgr when newBlockIndex fails to initialize the block index store (e.g., building index DB from existing block files or creating a fresh index). It wraps any error returned by newBlockIndex and aborts startup via panic, since the ledger cannot function without its index.","triggerScenarios":"Opening a ledger via newBlockStore/newBlockfileMgr when the index config is invalid, the index DB (LevelDB) is corrupted or locked, or reconstructing the index from block files fails (e.g., unreadable/corrupt blockfile segments).","commonSituations":"Corrupt or partially deleted indexDB directory after a crash; ledgerDataPath permissions problems; changed indexConfig in core.yaml vs previously built index; disk full or stale file locks from another peer process.","solutions":["Stop the peer and delete/repair the ledger's indexDB directory (ledgersData/chains/chains/<ledgerID>/index) so it is rebuilt from block files","Fix the indexConfig passed to newBlockIndex so it matches a supported configuration","Check filesystem permissions and free space for the ledger data directory","Ensure no other peer/process holds a lock on the LevelDB index store"],"exampleFix":"// before: index corrupt, peer panics on start\n// after: rebuild index cleanly\nsystemctl stop peer\nrm -rf /var/hyperledger/production/ledgersData/chains/chains/mychannel/index\nsystemctl start peer","handlingStrategy":"fallback","validationCode":"// before opening the ledger, sanity-check the index DB and permissions\nfunc checkIndexStore(rootDir string) error {\n\tidxDir := filepath.Join(rootDir, \"index\")\n\tif _, err := os.Stat(idxDir); err != nil {\n\t\treturn fmt.Errorf(\"index dir missing/corrupt: %w\", err)\n\t}\n\tf, err := os.Create(filepath.Join(idxDir, \".writecheck\"))\n\tif err != nil { return fmt.Errorf(\"index dir not writable/locked: %w\", err) }\n\tf.Close(); os.Remove(f.Name())\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        if strings.Contains(fmt.Sprint(r), \"error in block index\") {\n            log.Errorf(\"block index init failed: %v; rebuild indexDB from block files\", r)\n        }\n    }\n}()","preventionTips":["Never delete block files without also removing the index dir so it rebuilds","Ensure only one peer process accesses the ledger data directory","Monitor disk space and stop the peer cleanly (SIGTERM) before maintenance","Keep indexConfig stable across restarts; changing it requires index rebuild"],"tags":["hyperledger-fabric","ledger","block-index","panic","leveldb"],"backgroundTag":"leveldb-corruption","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"}