{"record":{"id":"18f02d8b16a36ff0","repo":"hyperledger/fabric","slug":"error-while-trying-to-check-the-presence-of-txid","errorCode":null,"errorMessage":"error while trying to check the presence of TXID [%s]","messagePattern":"error while trying to check the presence of TXID \\[(.+?)\\]","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/ledger/blkstorage/blockindex.go","lineNumber":235,"sourceCode":"\t\treturn peer.TxValidationCode(-1), 0, err\n\t}\n\treturn peer.TxValidationCode(v.TxValidationCode), blkNum, nil\n}\n\nfunc (index *blockIndex) txIDExists(txID string) (bool, error) {\n\tif !index.isAttributeIndexed(IndexableAttrTxID) {\n\t\treturn false, errors.New(\"transaction IDs not maintained in index\")\n\t}\n\trangeScan := constructTxIDRangeScan(txID)\n\titr, err := index.db.GetIterator(rangeScan.startKey, rangeScan.stopKey)\n\tif err != nil {\n\t\treturn false, errors.WithMessagef(err, \"error while trying to check the presence of TXID [%s]\", txID)\n\t}\n\tdefer itr.Release()\n\n\tpresent := itr.Next()\n\tif err := itr.Error(); err != nil {\n\t\treturn false, errors.Wrapf(err, \"error while trying to check the presence of TXID [%s]\", txID)\n\t}\n\treturn present, nil\n}\n\nfunc (index *blockIndex) getTxIDVal(txID string) (*TxIDIndexValue, uint64, error) {\n\tif !index.isAttributeIndexed(IndexableAttrTxID) {\n\t\treturn nil, 0, errors.New(\"transaction IDs not maintained in index\")\n\t}\n\trangeScan := constructTxIDRangeScan(txID)\n\titr, err := index.db.GetIterator(rangeScan.startKey, rangeScan.stopKey)\n\tif err != nil {\n\t\treturn nil, 0, errors.WithMessagef(err, \"error while trying to retrieve transaction info by TXID [%s]\", txID)\n\t}\n\tdefer itr.Release()\n\n\tpresent := itr.Next()\n\tif err := itr.Error(); err != nil {\n\t\treturn nil, 0, errors.Wrapf(err, \"error while trying to retrieve transaction info by TXID [%s]\", txID)","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/common/ledger/blkstorage/blockindex.go#L217-L253","documentation":"This is a wrapped error (errors.WithMessagef/Wrapf) from txIDExists: the underlying goleveldb iterator operation failed while scanning the txid key range. The original cause is embedded — typical roots include goleveldb 'DB closed', corrupted index DB files, or I/O errors.","triggerScenarios":"Calling txIDExists when index.db.GetIterator fails (e.g. database already closed, corrupted MANIFEST/log files) or itr.Error() reports an iterator-level failure during/after the range scan over constructTxIDRangeScan(txID) keys.","commonSituations":"Peer shutting down or restarted while a query is in flight; disk full or permission issues on the index DB directory; goleveldb corruption after unclean shutdown; concurrent open/close misuse of the store.","solutions":["Read the wrapped cause (errors.Unwrap / %v of the returned error) — fix the root DB/IO problem it names","If 'leveldb: closed', ensure the peer/store is running and queries are not issued after Close; reinitialize access via blkstorage provider","If corruption is indicated, stop the peer, back up and rebuild/reinitialize the index DB so syncIndex regenerates txid keys","Check disk space/permissions on the ledger data directory"],"exampleFix":"// before\nexists, err := store.TxIDExists(txid)\nif err != nil { log.Println(err) } // only shows wrapper message\n// after\nexists, err := store.TxIDExists(txid)\nif err != nil {\n    log.Printf(\"txid lookup failed for %s: %+v\", txid, err) // logs full cause chain\n    if strings.Contains(fmt.Sprint(err), \"closed\") { reopenProvider() }\n}","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"exists, err := store.TxIDExists(txid)\nvar dbErr *leveldb.errors // inspect cause chain\nif err != nil {\n    log.Printf(\"txid check failed: %+v\", err) // print full chain to expose root cause\n    if errors.Is(err, leveldb.ErrClosed) { return retryAfterReopen() }\n    return fmt.Errorf(\"index DB unhealthy; consider rebuild: %w\", err)\n}","preventionTips":["Always log wrapped errors with %+v to see the root goleveldb cause","Avoid issuing queries after provider/store Close during peer shutdown","Monitor disk space and clean shutdowns to prevent index DB corruption","Back up and rebuild the index DB if 'corrupted' appears in the cause chain"],"tags":["hyperledger-fabric","blockchain","leveldb","database-io"],"backgroundTag":"leveldb-iterator-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"}