Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.25k stars 4.59k forks source link

[BUG] Await when using Azure.Security.KeyVault.Certificates.GetCertificateAsync doesn't really wait for a success result #45405

Open DensedyGot opened 1 month ago

DensedyGot commented 1 month ago

Library name and version

Azure.Security.KeyVault.Certificates 4.6.0

Describe the bug

I tried to use these lines of code in an async method

            KeyVaultCertificateWithPolicy certificateWithPolicy = await certificateClient.GetCertificateAsync(HostConfigurations.CertificateName);
             KeyVaultSecret secret = await secretClient.GetSecretAsync(certificateWithPolicy.Name);

This will trigger an Error Exception on the next line because the first line dodn't provide a success certificateWithPolicy object to next line. As a workaround I have to insert additional code to wait for 2 seconds just to properly wait for the certificateWithPolicy object from first line to have a proper value like this

            KeyVaultCertificateWithPolicy certificateWithPolicy = await certificateClient.GetCertificateAsync(HostConfigurations.CertificateName);
            await Task.Delay(2000);
            KeyVaultSecret secret = await secretClient.GetSecretAsync(certificateWithPolicy.Name);

Expected behavior

There should be no need to put a Timer just to wait for the proper result from the first line

Actual behavior

Running the code without the Timer Delay will throw an Exception

Reproduction Steps

Run the API that will call the endpoint that uses the line of codes describe above.

Environment

Function App, Windows .NET 8

github-actions[bot] commented 1 month ago

Thank you for your feedback. Tagging and routing to the team member best able to assist.