Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Close() to also wait for view transactions and fix tests as well #91

Merged
merged 4 commits into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
12 changes: 8 additions & 4 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}

Expand Down
4 changes: 4 additions & 0 deletions tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -110,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.
Expand Down