-
-
Notifications
You must be signed in to change notification settings - Fork 141
Description
Describe the bug
If the initial login request fails, the client will be in an unusable state and additional calls to PerformImmediateLogin will return the same cached task and won't force a new login to occur.
VaultSharp Version
1.13.0.1
Vault Version
N/A
Does this work with Vault CLI?
N/A
Sample Code Snippet
while(ShouldRetry())
{
try
{
await vaultClient.PerformImmediateLogin();
Log("Login succeeded");
break;
}
catch(Exception e)
{
Log("Failed, retrying");
}
}
If the login fails, this will be stuck in an endless loop.
Exception Details/Stack Trace/Error Message
N/A
Any additional info
Polymath.PerformImmediateLogin evaluates the Lazy object to generate a Task to get a token (by calling GetVaultTokenAsync). If this login request fails (there's a known vault issue that can result in transient 401s) then the task will throw an exception. But since the Lazy was evaluated successfully, the faulted task will be cached and subsequent attempts to login will fail immediately.
For reference, the call path I'm seeing this in is our background token refresh logic loop. I create a new vault client then in a loop I attempt to login. I can reasonably easily just call ResetToken before attempting to login which should workaround this issue. However, I think the best bet would be to have the authentication task re-create the Lazy if it fails so that a subsequent calls will attempt to reauthenticate.
Another way to think about this is if you have a background thread that calls ResetVaultToken occasionally as suggested in the readme, then a login failure would cause all subsequent calls using that client to fail until the next time ResetVaultToken was called.