{"record":{"id":"3b0f263ddf00682c","repo":"hyperledger/fabric","slug":"ledger-not-opened-s","errorCode":null,"errorMessage":"Ledger not opened [%s]","messagePattern":"Ledger not opened \\[(.+?)\\]","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/ledger/ledgermgmt/ledger_mgmt.go","lineNumber":261,"sourceCode":"// Close closes all the opened ledgers and any resources held for ledger management\nfunc (m *LedgerMgr) Close() {\n\tlogger.Infof(\"Closing ledger mgmt\")\n\tm.lock.Lock()\n\tdefer m.lock.Unlock()\n\tfor _, l := range m.openedLedgers {\n\t\tl.Close()\n\t}\n\tm.ledgerProvider.Close()\n\tm.openedLedgers = nil\n\tlogger.Infof(\"ledger mgmt closed\")\n}\n\nfunc (m *LedgerMgr) getOpenedLedger(ledgerID string) (ledger.PeerLedger, error) {\n\tm.lock.Lock()\n\tdefer m.lock.Unlock()\n\tl, ok := m.openedLedgers[ledgerID]\n\tif !ok {\n\t\treturn nil, errors.Errorf(\"Ledger not opened [%s]\", ledgerID)\n\t}\n\treturn l, nil\n}\n\nfunc (m *LedgerMgr) closeLedger(ledgerID string) {\n\tm.lock.Lock()\n\tdefer m.lock.Unlock()\n\tl, ok := m.openedLedgers[ledgerID]\n\tif ok {\n\t\tl.Close()\n\t\tdelete(m.openedLedgers, ledgerID)\n\t}\n}\n\n// closableLedger extends from actual validated ledger and overwrites the Close method\ntype closableLedger struct {\n\tledgerMgr *LedgerMgr\n\tid        string","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/ledger/ledgermgmt/ledger_mgmt.go#L243-L279","documentation":"getOpenedLedger looks up the ledgerID in the manager's in-memory openedLedgers map; when the ledger has never been opened or has since been closed, it returns this error instead of opening it on demand. Callers such as GetDeployedChaincodeInfo require the ledger to already be open.","triggerScenarios":"Calling GetDeployedChaincodeInfo (or any path through getOpenedLedger) with a ledgerID whose ledger was closed (CloseLedger) or was never opened in this manager instance.","commonSituations":"Chaincode/lifecycle queries against a channel whose ledger was closed due to inactivity or shutdown; querying a channel ID with a typo; a query racing with ledger close during peer maintenance.","solutions":["Ensure the ledger is open first: call OpenLedger/Initialize (createOrOpenChains path) for the ledgerID before querying.","Verify the ledger ID matches an existing, open channel.","Handle the error by opening the ledger and retrying the operation."],"exampleFix":"// before\nlgr, err := mgr.GetDeployedChaincodeInfo(ledgerID, ccName)\n// after\nlgr, err := mgr.OpenLedger(ledgerID)\nif err != nil { return err }\ninfo, err := mgr.GetDeployedChaincodeInfo(ledgerID, ccName)","handlingStrategy":"fallback","validationCode":"if _, opened := openedLedgerIDs[ledgerID]; !opened {\n    if err := mgr.OpenLedger(ledgerID); err != nil { return err }\n}","typeGuard":null,"tryCatchPattern":"info, err := mgr.GetDeployedChaincodeInfo(ledgerID, cc)\nif err != nil && strings.Contains(err.Error(), \"Ledger not opened\") {\n    if _, oerr := mgr.OpenLedger(ledgerID); oerr != nil { return oerr }\n    info, err = mgr.GetDeployedChaincodeInfo(ledgerID, cc)\n}","preventionTips":["Open ledgers during startup (createOrOpenChains) before serving queries.","Validate ledger IDs against the list of joined channels.","Hold a reference to the opened ledger instead of relying on it staying cached."],"tags":["ledger","state","fabric"],"backgroundTag":"resource-not-open","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}