Skip to content

Commit

Permalink
Wait for goroutine to finish before db close
Browse files Browse the repository at this point in the history
Purge managment for private data state prefetches the information
about the data that is going to be expired in the next upcoming
block. This task is perfomed in a background goroutine. When the
ledger is closed, this task is not stopped and causes a nil pointer
panic inside goleveldb code.

This is a timing based issue and is observed in quite a few tines in
unit tests failures in CI. When the db.Close (issued by ledger close)
and db.NewIterator (issued by the background goroutine) functions are
invoked on goleveldb in parallel, this may happen that the Close function
makes the internal mem-buffers of goleveldb as nil followed by an access
to theses buffers by the function NewIterator.

As a fix, this CR makes the Close function to wait for the background
routine to finish.

FAB-11974 #done

Change-Id: I331476a6814ed2e6effcf10cc9310adb387722ff
Signed-off-by: manish <manish.sethi@gmail.com>
  • Loading branch information
manish-sethi committed Sep 14, 2018
1 parent 4c72480 commit 08aabe9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/ledger/kvledger/kv_ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func TestMain(m *testing.M) {
flogging.SetModuleLevel("statevalidator", "debug")
flogging.SetModuleLevel("valimpl", "debug")
flogging.SetModuleLevel("confighistory", "debug")
flogging.SetModuleLevel("pvtstatepurgemgmt", "debug")
viper.Set("peer.fileSystemPath", "/tmp/fabric/ledgertests/kvledger")
viper.Set("ledger.history.enableHistoryDatabase", true)
os.Exit(m.Run())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ func (txmgr *LockBasedTxMgr) invokeNamespaceListeners() error {

// Shutdown implements method in interface `txmgmt.TxMgr`
func (txmgr *LockBasedTxMgr) Shutdown() {
// wait for background go routine to finish else the timing issue causes a nil pointer inside goleveldb code
// see FAB-11974
txmgr.pvtdataPurgeMgr.WaitForPrepareToFinish()
txmgr.db.Close()
}

Expand Down

0 comments on commit 08aabe9

Please sign in to comment.