native: fix deadlock from leaving transactions open

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi 2022-03-23 15:48:42 -07:00
parent 439316c7af
commit fe426227d4

View File

@ -150,11 +150,17 @@ func (o *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
id, _, _, err := storage.GetInfo(ctx, key) id, _, _, err := storage.GetInfo(ctx, key)
if err != nil { if err != nil {
if rerr := t.Rollback(); rerr != nil {
log.G(ctx).WithError(rerr).Warn("failed to rollback transaction")
}
return err return err
} }
usage, err := fs.DiskUsage(ctx, o.getSnapshotDir(id)) usage, err := fs.DiskUsage(ctx, o.getSnapshotDir(id))
if err != nil { if err != nil {
if rerr := t.Rollback(); rerr != nil {
log.G(ctx).WithError(rerr).Warn("failed to rollback transaction")
}
return err return err
} }
@ -281,6 +287,9 @@ func (o *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
fs.WithXAttrErrorHandler(xattrErrorHandler), fs.WithXAttrErrorHandler(xattrErrorHandler),
} }
if err := fs.CopyDir(td, parent, copyDirOpts...); err != nil { if err := fs.CopyDir(td, parent, copyDirOpts...); err != nil {
if rerr := t.Rollback(); rerr != nil {
log.G(ctx).WithError(rerr).Warn("failed to rollback transaction")
}
return nil, fmt.Errorf("copying of parent failed: %w", err) return nil, fmt.Errorf("copying of parent failed: %w", err)
} }
} }