Skip to content

Commit 22c5a17

Browse files
authored
Merge pull request #108 from ipfs/chore/log-finalizer
Log error if batch not committed or canceled
2 parents 8a4303f + 78c54b5 commit 22c5a17

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

datastore.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,10 @@ func (d *Datastore) Batch() (ds.Batch, error) {
409409
b := &batch{d, d.DB.NewWriteBatch()}
410410
// Ensure that incomplete transaction resources are cleaned up in case
411411
// batch is abandoned.
412-
runtime.SetFinalizer(b, func(b *batch) { b.cancel() })
412+
runtime.SetFinalizer(b, func(b *batch) {
413+
b.cancel()
414+
log.Error("batch not committed or canceled")
415+
})
413416

414417
return b, nil
415418
}
@@ -481,8 +484,10 @@ func (b *batch) commit() error {
481484
if err != nil {
482485
// Discard incomplete transaction held by b.writeBatch
483486
b.cancel()
487+
return err
484488
}
485-
return err
489+
runtime.SetFinalizer(b, nil)
490+
return nil
486491
}
487492

488493
func (b *batch) Cancel() error {
@@ -498,6 +503,7 @@ func (b *batch) Cancel() error {
498503

499504
func (b *batch) cancel() {
500505
b.writeBatch.Cancel()
506+
runtime.SetFinalizer(b, nil)
501507
}
502508

503509
var _ ds.Datastore = (*txn)(nil)

0 commit comments

Comments
 (0)