Skip to content

Commit d14d89b

Browse files
cendhumanish-sethi
authored andcommittedJun 8, 2018
[FAB-10574] txmgr: rel lock only if it was acquir.
In the transaction manager, we need to release the write lock only if the lock was acquired. When an error occurs before acquiring a lock and if we try to release the unacquired lock in the defer statement, we would end up printing the wrong panic message (i.e., fatal error: sync: unlock of unlocked mutex) which would be less helpful during troubleshooting. Change-Id: I7b69f6a229a6edce374a960d1467a09057bfe25e Signed-off-by: senthil <cendhu@gmail.com>
1 parent d7656e2 commit d14d89b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed
 

‎core/ledger/kvledger/txmgmt/txmgr/lockbasedtxmgr/lockbased_txmgr.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ func (txmgr *LockBasedTxMgr) Commit() error {
141141
txmgr.pvtdataPurgeMgr.PrepareForExpiringKeys(txmgr.current.blockNum() + 1)
142142
logger.Debugf("Cleared version cache and launched the background routine for preparing keys to purge with the next block")
143143
txmgr.reset()
144-
txmgr.commitRWLock.Unlock()
145144
}()
146145

147146
logger.Debugf("Committing updates to state database")
@@ -155,6 +154,7 @@ func (txmgr *LockBasedTxMgr) Commit() error {
155154
}
156155

157156
txmgr.commitRWLock.Lock()
157+
defer txmgr.commitRWLock.Unlock()
158158
logger.Debugf("Write lock acquired for committing updates to state database")
159159
commitHeight := version.NewHeight(txmgr.current.blockNum(), txmgr.current.maxTxNumber())
160160
if err := txmgr.db.ApplyPrivacyAwareUpdates(txmgr.current.batch, commitHeight); err != nil {

0 commit comments

Comments
 (0)
Please sign in to comment.