From 449f9fc31c0d737d2094b4c0db7a207b3e764122 Mon Sep 17 00:00:00 2001 From: Koloss5421 Date: Mon, 11 Mar 2024 18:40:25 -0500 Subject: [PATCH] fix(vm): timeout when resizing a disk during clone (#1103) Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Co-authored-by: Koloss5421 --- proxmox/nodes/vms/vms.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/proxmox/nodes/vms/vms.go b/proxmox/nodes/vms/vms.go index 81db4301..2b632c85 100644 --- a/proxmox/nodes/vms/vms.go +++ b/proxmox/nodes/vms/vms.go @@ -16,6 +16,7 @@ import ( "strings" "time" + "github.com/avast/retry-go/v4" "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/bpg/terraform-provider-proxmox/proxmox/api" @@ -262,12 +263,22 @@ func (c *Client) RebootVMAsync(ctx context.Context, d *RebootRequestBody) (*stri // ResizeVMDisk resizes a virtual machine disk. func (c *Client) ResizeVMDisk(ctx context.Context, d *ResizeDiskRequestBody, timeout int) error { - taskID, err := c.ResizeVMDiskAsync(ctx, d) - if err != nil { - return err - } + err := retry.Do(func() error { + taskID, err := c.ResizeVMDiskAsync(ctx, d) + if err != nil { + return err + } - err = c.Tasks().WaitForTask(ctx, *taskID, timeout, 5) + //nolint:wrapcheck + return c.Tasks().WaitForTask(ctx, *taskID, timeout, 5) + }, + retry.Attempts(3), + retry.Delay(1*time.Second), + retry.LastErrorOnly(false), + retry.RetryIf(func(err error) bool { + return strings.Contains(err.Error(), "got timeout") + }), + ) if err != nil { return fmt.Errorf("error waiting for VM disk resize: %w", err) }