From 5160ff330c3b1a91e1cc2e2b6273021617dc79d0 Mon Sep 17 00:00:00 2001 From: Paul <pvansanten@gmail.com> Date: Thu, 29 Mar 2018 22:31:27 +0200 Subject: [PATCH 1/4] Fix testDB_Close_PendingTx to do something with the writable arg and stop it from closing twice --- db_test.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/db_test.go b/db_test.go index e3a58c3ca..711ae45b7 100644 --- a/db_test.go +++ b/db_test.go @@ -662,10 +662,9 @@ func TestDB_Close_PendingTx_RO(t *testing.T) { testDB_Close_PendingTx(t, false) // Ensure that a database cannot close while transactions are open. func testDB_Close_PendingTx(t *testing.T, writable bool) { db := MustOpenDB() - defer db.MustClose() // Start transaction. - tx, err := db.Begin(true) + tx, err := db.Begin(writable) if err != nil { t.Fatal(err) } @@ -687,8 +686,13 @@ func testDB_Close_PendingTx(t *testing.T, writable bool) { default: } - // Commit transaction. - if err := tx.Commit(); err != nil { + // Commit/close transaction. + if writable { + err = tx.Commit() + } else { + err = tx.Rollback() + } + if err != nil { t.Fatal(err) } From 2f96b603f89057ed6348f56c184618c5f9cf02af Mon Sep 17 00:00:00 2001 From: Paul <pvansanten@gmail.com> Date: Thu, 29 Mar 2018 22:32:34 +0200 Subject: [PATCH 2/4] Fix Close() to wait for view transactions by getting a full lock on mmaplock --- db.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db.go b/db.go index ab97c6014..b37074ee0 100644 --- a/db.go +++ b/db.go @@ -454,8 +454,8 @@ func (db *DB) Close() error { db.metalock.Lock() defer db.metalock.Unlock() - db.mmaplock.RLock() - defer db.mmaplock.RUnlock() + db.mmaplock.Lock() + defer db.mmaplock.Unlock() return db.close() } From 5929e0311764408380f6c6c6df1f226d0082d36f Mon Sep 17 00:00:00 2001 From: Paul <pvansanten@gmail.com> Date: Thu, 29 Mar 2018 23:13:39 +0200 Subject: [PATCH 3/4] Fix the TestTx_Check_ReadOnly to close the view transaction --- tx_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tx_test.go b/tx_test.go index de92cb535..e506a09c6 100644 --- a/tx_test.go +++ b/tx_test.go @@ -57,6 +57,8 @@ func TestTx_Check_ReadOnly(t *testing.T) { t.Fatal(err) } } + // Close the view transaction + tx.Rollback() } // Ensure that committing a closed transaction returns an error. From cabe88ebc3f71ad7d6f691159be17eabdb222114 Mon Sep 17 00:00:00 2001 From: Paul <pvansanten@gmail.com> Date: Thu, 29 Mar 2018 23:37:10 +0200 Subject: [PATCH 4/4] Fix the TestTx_Commit_ErrTxNotWritable to close the view transaction --- tx_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tx_test.go b/tx_test.go index e506a09c6..2bf89ceee 100644 --- a/tx_test.go +++ b/tx_test.go @@ -112,6 +112,8 @@ func TestTx_Commit_ErrTxNotWritable(t *testing.T) { if err := tx.Commit(); err != bolt.ErrTxNotWritable { t.Fatal(err) } + // Close the view transaction + tx.Rollback() } // Ensure that a transaction can retrieve a cursor on the root bucket.