Description
openedon Jan 26, 2021
Describe the bug
I have built a test app in which I call IResourceManagementClient.ResourceGroups.ListAsync in a loop using a service principal.
From portal I created 2 resource groups A and B
From portal I assign rgA owner role to service principal
I start the test app. I will not restart or stop the app until end of the test.
As expected the app reports there is only one resource group
From portal I assign rgB owner role to service principal
At this point I expect the app to report 2 resource groups (A&B) but sometimes it reports only 1 sometimes 2 which seems random.
Now I restart the app which removes the randomness
I have similar results if I remove owner role from one of the resources groups: I get inconsistent reports of 1 and 2 resource groups.
Code Snippet
static async Task TestAzureAsync()
{
const string clientId = "***";
const string clientSecret = "***";
const string tenantId = "***";
const string subscriptionId = "***";
for (int i = 0; i < 1000; ++i)
{
// TokenCache.DefaultShared.Clear(); // <- workaround
try
{
var credentials = SdkContext.AzureCredentialsFactory
.FromServicePrincipal(
clientId,
clientSecret,
tenantId,
AzureEnvironment.AzureGlobalCloud);
RestClient restClient = RestClient.Configure()
.WithEnvironment(AzureEnvironment.AzureGlobalCloud)
.WithCredentials(credentials)
.WithUserAgent(Guid.NewGuid().ToString(), "1")
.Build();
var client = new ResourceManagementClient(restClient)
{ SubscriptionId = subscriptionId };
var rgs = await client.ResourceGroups.ListAsync();
Console.WriteLine($"Count: {rgs.Count()}");
}
catch (Exception ex)
{
Console.WriteLine("Exception");
}
await Task.Delay(TimeSpan.FromMilliseconds(100));
}
}
Setup (please complete the following information):
Include="Microsoft.Azure.Management.Fluent" Version="1.36.1"