Skip to content

Commit

Permalink
fix deadlock and add more logging (#5160)
Browse files Browse the repository at this point in the history
  • Loading branch information
Googlom authored Oct 24, 2024
1 parent 4990b2d commit 0c41f9c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions pkg/vault/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,18 @@ func NewClientWithToken(cfg *ClientConfig, token string) (*Client, error) {
func (c *Client) startTokenLifecycleManager(initialLoginDone chan struct{}) {
defer func() {
// make sure to close channel to avoid blocking of the caller
_, open := <-initialLoginDone
if open {
close(initialLoginDone)
}
log.Entry().Debugf("exiting Vault token lifecycle manager")
initialLoginDone <- struct{}{}
close(initialLoginDone)
}()

initialLoginSucceed := false
for i := 0; i < c.vaultApiClient.MaxRetries(); i++ {
retryAttemptDuration := c.vaultApiClient.MinRetryWait()
for i := 0; i <= c.vaultApiClient.MaxRetries(); i++ {
if i != 0 {
log.Entry().Infof("Retrying Vault login. Attempt %d of %d", i, c.vaultApiClient.MaxRetries())
log.Entry().Infof("Retrying Vault login in %.0f seconds. Attempt %d of %d",
retryAttemptDuration.Seconds(), i, c.vaultApiClient.MaxRetries())
time.Sleep(retryAttemptDuration)
}

vaultLoginResp, err := c.login()
Expand All @@ -101,7 +103,6 @@ func (c *Client) startTokenLifecycleManager(initialLoginDone chan struct{}) {
}
if !initialLoginSucceed {
initialLoginDone <- struct{}{}
close(initialLoginDone)
initialLoginSucceed = true
}

Expand Down

0 comments on commit 0c41f9c

Please sign in to comment.