Skip to content

Commit

Permalink
Handler error in writeBatch.Flush (#1421)
Browse files Browse the repository at this point in the history
The writeBatch.Flush was skipping the error returned by wb.Commit() call.
We shouldn't ignore the error.
  • Loading branch information
Ibrahim Jarif authored Jul 16, 2020
1 parent 82dec91 commit 8b7a013
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ func (wb *WriteBatch) commit() error {
return wb.err
}
if err := wb.throttle.Do(); err != nil {
return err
wb.err = err
return wb.err
}
wb.txn.CommitWith(wb.callback)
wb.txn = wb.db.newTransaction(true, wb.isManaged)
Expand All @@ -193,11 +194,15 @@ func (wb *WriteBatch) commit() error {
// returns any error stored by WriteBatch.
func (wb *WriteBatch) Flush() error {
wb.Lock()
// commit will set the wb.err so no need to check the error here.
_ = wb.commit()
wb.txn.Discard()
wb.Unlock()

if err := wb.throttle.Finish(); err != nil {
if wb.err != nil {
return errors.Errorf("wb.err: %s err: %s", wb.err, err)
}
return err
}

Expand Down

0 comments on commit 8b7a013

Please sign in to comment.