File tree 1 file changed +8
-2
lines changed
1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -409,7 +409,10 @@ func (d *Datastore) Batch() (ds.Batch, error) {
409
409
b := & batch {d , d .DB .NewWriteBatch ()}
410
410
// Ensure that incomplete transaction resources are cleaned up in case
411
411
// 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
+ })
413
416
414
417
return b , nil
415
418
}
@@ -481,8 +484,10 @@ func (b *batch) commit() error {
481
484
if err != nil {
482
485
// Discard incomplete transaction held by b.writeBatch
483
486
b .cancel ()
487
+ return err
484
488
}
485
- return err
489
+ runtime .SetFinalizer (b , nil )
490
+ return nil
486
491
}
487
492
488
493
func (b * batch ) Cancel () error {
@@ -498,6 +503,7 @@ func (b *batch) Cancel() error {
498
503
499
504
func (b * batch ) cancel () {
500
505
b .writeBatch .Cancel ()
506
+ runtime .SetFinalizer (b , nil )
501
507
}
502
508
503
509
var _ ds.Datastore = (* txn )(nil )
You can’t perform that action at this time.
0 commit comments