{"record":{"id":"e90b7404e30e5774","repo":"hyperledger/fabric","slug":"error-getting-next-element-out-of-private-data-ite","errorCode":null,"errorMessage":"error getting next element out of private data iterator, namespace <%s>, collection name <%s>, txID <%s>, due to <%s>","messagePattern":"error getting next element out of private data iterator, namespace <(.+?)>, collection name <(.+?)>, txID <(.+?)>, due to <(.+?)>","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gossip/privdata/dataretriever.go","lineNumber":186,"sourceCode":"\t}\n\n\treturn results, nil\n}\n\nfunc (dr *dataRetriever) fromTransientStore(dig *protosgossip.PvtDataDigest, filter map[string]ledger.PvtCollFilter) (*util.PrivateRWSetWithConfig, error) {\n\tresults := &util.PrivateRWSetWithConfig{}\n\tit, err := dr.store.GetTxPvtRWSetByTxid(dig.TxId, filter)\n\tif err != nil {\n\t\treturn nil, errors.Errorf(\"was not able to retrieve private data from transient store, namespace <%s>\"+\n\t\t\t\", collection name %s, txID <%s>, due to <%s>\", dig.Namespace, dig.Collection, dig.TxId, err)\n\t}\n\tdefer it.Close()\n\n\tmaxEndorsedAt := uint64(0)\n\tfor {\n\t\tres, err := it.Next()\n\t\tif err != nil {\n\t\t\treturn nil, errors.Errorf(\"error getting next element out of private data iterator, namespace <%s>\"+\n\t\t\t\t\", collection name <%s>, txID <%s>, due to <%s>\", dig.Namespace, dig.Collection, dig.TxId, err)\n\t\t}\n\t\tif res == nil {\n\t\t\treturn results, nil\n\t\t}\n\t\trws := res.PvtSimulationResultsWithConfig\n\t\tif rws == nil {\n\t\t\tdr.logger.Debug(\"Skipping nil PvtSimulationResultsWithConfig received at block height\", res.ReceivedAtBlockHeight)\n\t\t\tcontinue\n\t\t}\n\t\ttxPvtRWSet := rws.PvtRwset\n\t\tif txPvtRWSet == nil {\n\t\t\tdr.logger.Debug(\"Skipping empty PvtRwset of PvtSimulationResultsWithConfig received at block height\", res.ReceivedAtBlockHeight)\n\t\t\tcontinue\n\t\t}\n\n\t\tcolConfigs, found := rws.CollectionConfigs[dig.Namespace]\n\t\tif !found {","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/gossip/privdata/dataretriever.go#L168-L204","documentation":"While iterating results from the transient store, it.Next() can fail (iterator corruption, store mutation/close mid-iteration). The retriever aborts and reports the namespace, collection, txID and wrapped cause. This happens after the iterator was created successfully, so it indicates a mid-iteration storage failure.","triggerScenarios":"it.Next() returns a non-nil error while paging through the private-data iterator — concurrent store close/shutdown, leveldb iterator failure, or corrupted pvt simulation records.","commonSituations":"Peer shutdown racing an in-flight gossip pull; an unclean crash leaving leveldb in a state where iterators fail; transient store files on failing storage.","solutions":["Retry the pull once gossip/the peer is idle — shutdown races are transient.","Restart the peer to recreate leveldb iterators over a clean state.","Check disk health and transient store directory integrity.","If corruption persists, rebuild peer DBs and re-fetch pvt data from other peers."],"exampleFix":"// before\nres, err := it.Next()\nif err != nil {\n    return nil, errors.Errorf(\"error getting next element ...\")\n}\n\n// after: safe iteration with close before retry\nres, err := it.Next()\nif err != nil {\n    logger.Warningf(\"iterator failed for %s: %v\", dig.TxId, err)\n    it.Close()\n    return nil, nil // allow gossip pull retry\n}","handlingStrategy":"retry","validationCode":"it, err := store.GetTxPvtRWSetByTxid(txid, filter)\nif err != nil {\n    return err\n}\ndefer it.Close() // close before any retry to avoid iterator leaks","typeGuard":"func iteratorExhausted(it ledger.ResultsIterator) (bool, error) {\n    res, err := it.Next()\n    if err != nil {\n        return false, err\n    }\n    return res == nil, nil\n}","tryCatchPattern":"res, err := it.Next()\nif err != nil {\n    it.Close()\n    logger.Warningf(\"iterator error for %s (%v); retrying pull\", dig.TxId, err)\n    scheduleRetry()\n    return\n}","preventionTips":["Always defer it.Close() immediately after creating an iterator.","Avoid concurrent store close during iteration — use graceful peer shutdown.","Monitor disk health for the leveldb backing the transient store.","Cap retry loops so corrupted iterators don't spin indefinitely."],"tags":["fabric","transient-store","iterator","private-data"],"backgroundTag":"transient-store-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"}