From 94cf25f7dbbf31e110eda27007b8bb3538ee29c4 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Wed, 14 Mar 2018 13:36:49 -0700 Subject: [PATCH] overlay: fix cleanup directory deletion race Fixes a bug where a writable transaction may create or make changes to a directory while the cleanup is running, leading to removal of a directory which will be referenced. Signed-off-by: Derek McGowan --- snapshots/overlay/overlay.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/snapshots/overlay/overlay.go b/snapshots/overlay/overlay.go index 497cd475f..0650e7878 100644 --- a/snapshots/overlay/overlay.go +++ b/snapshots/overlay/overlay.go @@ -309,7 +309,9 @@ func (o *snapshotter) Cleanup(ctx context.Context) error { } func (o *snapshotter) cleanupDirectories(ctx context.Context) ([]string, error) { - ctx, t, err := o.ms.TransactionContext(ctx, false) + // Get a write transaction to ensure no other write transaction can be entered + // while the cleanup is scanning. + ctx, t, err := o.ms.TransactionContext(ctx, true) if err != nil { return nil, err }