Skip to content

Commit 17737a5

Browse files
committed
Closing ledger multiple times results in panic
An initial fix to avoid the panic. See JIRA for further details regarding why the ledger is being closed more than once. I'm not familiar enough with gossip at the moment to determine the proper plan of action for the code that's causing this. FAB-15915 Change-Id: I79a0009b7fec401b0351d96ee7f1a495ccf05c98 Signed-off-by: Will Lahti <wtlahti@us.ibm.com>
1 parent 64e5d9b commit 17737a5

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

core/ledger/ledgermgmt/ledger_mgmt.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,11 @@ func (m *LedgerMgr) getOpenedLedger(ledgerID string) (ledger.PeerLedger, error)
164164
func (m *LedgerMgr) closeLedger(ledgerID string) {
165165
m.lock.Lock()
166166
defer m.lock.Unlock()
167-
l := m.openedLedgers[ledgerID]
168-
l.Close()
169-
delete(m.openedLedgers, ledgerID)
167+
l, ok := m.openedLedgers[ledgerID]
168+
if ok {
169+
l.Close()
170+
delete(m.openedLedgers, ledgerID)
171+
}
170172
}
171173

172174
// closableLedger extends from actual validated ledger and overwrites the Close method

core/ledger/ledgermgmt/ledger_mgmt_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ func TestLedgerMgmt(t *testing.T) {
5454

5555
l := ledgers[2]
5656
l.Close()
57+
// attempt to close the same ledger twice and ensure it doesn't panic
58+
assert.NotPanics(t, l.Close)
59+
5760
l, err = ledgerMgr.OpenLedger(ledgerID)
5861
assert.NoError(t, err)
5962

0 commit comments

Comments
 (0)