overlay: call rollback on commit error
Rollback was not being called when the function was called with
a key which does not exist. This failure to call rollback kept
the database open and caused all new requests to block.
@@ -152,6 +152,14 @@ func (o *snapshotter) Commit(ctx context.Context, name, key string) error {
return err
}
+ defer func() {
+ if err != nil {
+ if rerr := t.Rollback(); rerr != nil {
+ log.G(ctx).WithError(rerr).Warn("Failure rolling back transaction")
+ }
+ }
+ }()
+
// grab the existing id
id, _, _, err := storage.GetInfo(ctx, key)
if err != nil {
@@ -163,10 +171,7 @@ func (o *snapshotter) Commit(ctx context.Context, name, key string) error {
return err
}
- if _, err := storage.CommitActive(ctx, key, name, snapshot.Usage(usage)); err != nil {
- if rerr := t.Rollback(); rerr != nil {
- log.G(ctx).WithError(rerr).Warn("Failure rolling back transaction")
- }
+ if _, err = storage.CommitActive(ctx, key, name, snapshot.Usage(usage)); err != nil {
return errors.Wrap(err, "failed to commit snapshot")
}
return t.Commit()
