Skip to content

Commit

Permalink
mvcc/backend: remove t.tx.DB()==nil checks with GracefulStop
Browse files Browse the repository at this point in the history
Revert #6662.

Signed-off-by: Gyu-Ho Lee <[email protected]>
  • Loading branch information
gyuho committed Apr 15, 2017
1 parent eda2ec7 commit 5aea157
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions mvcc/backend/batch_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,12 @@ func (t *batchTx) commit(stop bool) {
t.backend.mu.RLock()
defer t.backend.mu.RUnlock()

// 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())
}
// t.tx.DB()==nil if 'CommitAndStop' calls 'batchTx.commit(true)',
// which initializes *bolt.Tx.db and *bolt.Tx.meta as nil; panics t.tx.Size().
// Server must make sure 'batchTx.commit(false)' does not follow
// 'batchTx.commit(true)' (e.g. stopping backend, and inflight Hash call).
// etcd/embed ensures all inflight gRPC requests are handled via 'GracefulStop'.
atomic.StoreInt64(&t.backend.size, t.tx.Size())
return
}

Expand Down

0 comments on commit 5aea157

Please sign in to comment.