Skip to content

Commit

Permalink
backend: skip *bolt.DB.Size call when nil
Browse files Browse the repository at this point in the history
  • Loading branch information
gyuho committed Oct 21, 2016
1 parent 791aeb3 commit 7d30326
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion mvcc/backend/batch_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,20 @@ func (t *batchTx) commit(stop bool) {
if t.pending == 0 && !stop {
t.backend.mu.RLock()
defer t.backend.mu.RUnlock()
atomic.StoreInt64(&t.backend.size, t.tx.Size())

// batchTx.commit(true) calls *bolt.Tx.Commit, which
// initializes *bolt.Tx.db and *bolt.Tx.meta as nil,
// and subsequent *bolt.Tx.Size() call panics.
//
// This nil pointer reference panic happens when:
// 1. batchTx.commit(false) from newBatchTx
// 2. batchTx.commit(true) from stopping backend
// 3. batchTx.commit(false) from inflight mvcc Hash call
//
// Check if db is nil to prevent this panic
if t.tx.DB() != nil {
atomic.StoreInt64(&t.backend.size, t.tx.Size())
}
return
}
start := time.Now()
Expand Down

0 comments on commit 7d30326

Please sign in to comment.