From 355807410298b01c8e3c0ac2ffeb51337f50239f Mon Sep 17 00:00:00 2001 From: k-yomo Date: Tue, 30 Aug 2022 18:43:23 +0900 Subject: [PATCH] Fix to unlock when returning error --- internal/provider/resource_virtual_index.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/provider/resource_virtual_index.go b/internal/provider/resource_virtual_index.go index 6e08a77..45fc964 100644 --- a/internal/provider/resource_virtual_index.go +++ b/internal/provider/resource_virtual_index.go @@ -574,6 +574,7 @@ func resourceVirtualIndexCreate(ctx context.Context, d *schema.ResourceData, m i mutexKV.Lock(ctx, algoliaIndexMutexKey(apiClient.appID, primaryIndexName)) primaryIndexSettings, err := primaryIndex.GetSettings(ctx) if err != nil { + mutexKV.Unlock(ctx, algoliaIndexMutexKey(apiClient.appID, primaryIndexName)) return diag.FromErr(err) } replicas := primaryIndexSettings.Replicas.Get() @@ -584,9 +585,11 @@ func resourceVirtualIndexCreate(ctx context.Context, d *schema.ResourceData, m i Replicas: opt.Replicas(newReplicas...), }) if err != nil { + mutexKV.Unlock(ctx, algoliaIndexMutexKey(apiClient.appID, primaryIndexName)) return diag.FromErr(err) } if err := res.Wait(); err != nil { + mutexKV.Unlock(ctx, algoliaIndexMutexKey(apiClient.appID, primaryIndexName)) return diag.FromErr(err) } }