From e87bc4b941564aace95d60ff987b7ec0d508b437 Mon Sep 17 00:00:00 2001 From: Leah <8845940+ForsakenHarmony@users.noreply.github.com> Date: Wed, 27 Mar 2024 23:27:07 +0100 Subject: [PATCH] fix: prevent authenticating multiple times in parallel (#1168) Signed-off-by: hrmny <8845940+ForsakenHarmony@users.noreply.github.com> --- proxmox/api/ticket_auth.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/proxmox/api/ticket_auth.go b/proxmox/api/ticket_auth.go index 9ae32b52..642a6eab 100644 --- a/proxmox/api/ticket_auth.go +++ b/proxmox/api/ticket_auth.go @@ -14,6 +14,7 @@ import ( "fmt" "net/http" "net/url" + "sync" "github.com/hashicorp/terraform-plugin-log/tflog" @@ -24,6 +25,8 @@ type ticketAuthenticator struct { conn *Connection authRequest string authData *AuthenticationResponseData + + mu sync.Mutex } // NewTicketAuthenticator returns a new ticket authenticator. @@ -46,6 +49,9 @@ func NewTicketAuthenticator(conn *Connection, creds *Credentials) (Authenticator } func (t *ticketAuthenticator) authenticate(ctx context.Context) (*AuthenticationResponseData, error) { + t.mu.Lock() + defer t.mu.Unlock() + if t.authData != nil { return t.authData, nil }