I have created a C# program to manage secrets - AKA password Manager.
As it is a website I am using the keyvaultclient methods.
I believe I am getting a race condition between deleting a secret via DeleteSecretAsync and PurgeDeletedSecretAsync.
If I use the debugger and step between the two calls, all is good.
If I just let the program run, I get an exception raised - Microsoft.Azure.KeyVault.Models.KeyVaultErrorException: Operation returned an invalid status code 'Conflict'
Both operations are in seperate async threading tasks and I await the calls to both tasks - the actual operations within the tasks are also awaited.
Note: I have only recently started using C# - I am better with C, VB!
I tried a 1 second sleep between the calls - but that made no difference.
Code below; Note that commented code is what I used before adding the two tasks - obviously that did not work!
//var secretBundle = await Global.kv.DeleteSecretAsync(Global.keyVaultName, SecretToDelete);
System.Threading.Tasks.Task T1 = DeleteSecret(SecretToDelete);
await T1;
// await Global.kv.PurgeDeletedSecretAsync(secretBundle.RecoveryId);
System.Threading.Tasks.Task T = PurgeSecret(Global.savedSecret);
await T;
return RedirectToAction("Index");
}
private async System.Threading.Tasks.Task DeleteSecret(string secret)
{
var secretBundle = await Global.kv.DeleteSecretAsync(Global.keyVaultName, secret);
Global.savedSecret=secretBundle.RecoveryId;
}
private async System.Threading.Tasks.Task PurgeSecret(string secret)
{
await Global.kv.PurgeDeletedSecretAsync(secret);
}