From 8cc5ecec2352e1c837aa778c6bb9402ac0be2191 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Wed, 30 Oct 2019 19:40:57 +0100 Subject: [PATCH] xl: Fix locking in xl HealObject (#8455) Move locking to the correct location, before loading object data. --- cmd/xl-v1-healing.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/cmd/xl-v1-healing.go b/cmd/xl-v1-healing.go index bc17e7ea4..32f2e96f3 100644 --- a/cmd/xl-v1-healing.go +++ b/cmd/xl-v1-healing.go @@ -679,6 +679,14 @@ func (xl xlObjects) HealObject(ctx context.Context, bucket, object string, dryRu } healCtx := logger.SetReqInfo(context.Background(), newReqInfo) + // Lock the object before healing. Use read lock since healing + // will only regenerate parts & xl.json of outdated disks. + objectLock := xl.nsMutex.NewNSLock(ctx, bucket, object) + if lerr := objectLock.GetRLock(globalHealingTimeout); lerr != nil { + return madmin.HealResultItem{}, lerr + } + defer objectLock.RUnlock() + // Healing directories handle it separately. if hasSuffix(object, SlashSeparator) { return xl.healObjectDir(healCtx, bucket, object, dryRun) @@ -707,13 +715,6 @@ func (xl xlObjects) HealObject(ctx context.Context, bucket, object string, dryRu return defaultHealResult(xlMetaV1{}, storageDisks, errs, bucket, object), toObjectErr(err, bucket, object) } - // Lock the object before healing. - objectLock := xl.nsMutex.NewNSLock(ctx, bucket, object) - if lerr := objectLock.GetRLock(globalHealingTimeout); lerr != nil { - return defaultHealResult(latestXLMeta, storageDisks, errs, bucket, object), lerr - } - defer objectLock.RUnlock() - errCount := 0 for _, err := range errs { if err != nil {