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 {