{"record":{"id":"e8e39c2be4cbda82","repo":"hyperledger/fabric","slug":"could-not-open-writer-to-current-file-s","errorCode":null,"errorMessage":"Could not open writer to current file: %s","messagePattern":"Could not open writer to current file: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"common/ledger/blkstorage/blockfile_mgr.go","lineNumber":125,"sourceCode":"\t}\n\tif blockfilesInfo == nil {\n\t\tlogger.Info(`Getting block information from block storage`)\n\t\tif blockfilesInfo, err = constructBlockfilesInfo(rootDir); err != nil {\n\t\t\tpanic(fmt.Sprintf(\"Could not build blockfilesInfo info from block files: %s\", err))\n\t\t}\n\t\tlogger.Debugf(\"Info constructed by scanning the blocks dir = %s\", spew.Sdump(blockfilesInfo))\n\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","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/common/ledger/blkstorage/blockfile_mgr.go#L107-L143","documentation":"Panic when newBlockfileWriter cannot open (create/append) the current block file (blockfile_<latestFileNumber>) for the ledger. Without the writer, new blocks cannot be appended and block storage init fails.","triggerScenarios":"newBlockfileWriter returns an error opening deriveBlockfilePath(rootDir, latestFileNumber): permission denied, read-only fs, I/O error, or invalid path during newBlockfileMgr.","commonSituations":"chains/<ledgerID> dir not writable by the peer; read-only mounted volume; disk/device failure; wrong user after container image change or migration.","solutions":["Grant the peer user write permission on the ledger's chains dir (chown/chmod)","Mount the ledger volume read-write and check free disk space","If the path is wrong (config pointing at wrong dir), fix core.yaml fileLedger settings"],"exampleFix":"// before: running peer as non-root on root-owned data\n// after:\n// sudo chown -R peer:peer /var/hyperledger/production/ledgersData && systemctl start peer","handlingStrategy":"validation","validationCode":"currentPath := deriveBlockfilePath(rootDir, latestFileNumber)\nf, err := os.OpenFile(currentPath, os.O_RDWR|os.O_CREATE, 0o644)\nif err != nil {\n    return fmt.Errorf(\"cannot open current block file %s: %w\", currentPath, err)\n}\nf.Close()","typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        err = fmt.Errorf(\"block file writer init failed: %v\", r)\n    }\n}()","preventionTips":["Ensure the peer user can create files in chains/<ledgerID>","Provision free disk space before peer start (new block files are created here)","Avoid read-only rootfs for the ledger path in containers"],"tags":["filesystem","permissions","panic"],"backgroundTag":"file-open-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"}