azure-sdk-for-net icon indicating copy to clipboard operation
azure-sdk-for-net copied to clipboard

[BUG] AppService GetSiteInstances Throws Invalid URI error

Open mwgustin opened this issue 2 years ago • 8 comments

Library name and version

Azure.ResourceManager.AppService

Describe the bug

I am trying to get the list of instances from an app services but the SDK is failing when trying to return the list. It throws an Invalid/Empty URI exception.

Additionally, I have tried to get specific instances using known Instance Names, but that also fails with a Null Argument Exception on 'resourceId'.

Expected behavior

Return list of instances/specific instance

Actual behavior

GetSiteInstances foreach list:

Error: System.UriFormatException: Invalid URI: The URI is empty.
   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)
   at System.Uri..ctor(String uriString)
   at Azure.ResourceManager.AppService.WebSiteInstanceStatusData.DeserializeWebSiteInstanceStatusData(JsonElement element)
   at Azure.ResourceManager.AppService.Models.WebAppInstanceStatusCollection.DeserializeWebAppInstanceStatusCollection(JsonElement element)
   at Azure.ResourceManager.AppService.WebAppsRestOperations.ListInstanceIdentifiers(String subscriptionId, String resourceGroupName, String name, CancellationToken cancellationToken)
   at Azure.ResourceManager.AppService.SiteInstanceCollection.<>c__DisplayClass8_0.<GetAll>g__FirstPageFunc|0(Nullable`1 pageSizeHint)
   at Azure.Core.PageableHelpers.FuncPageable`1.AsPages(String continuationToken, Nullable`1 pageSizeHint)+MoveNext()
   at Azure.Pageable`1.GetEnumerator()+MoveNext()
   at Submission#63.<<Initialize>>d__0.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)

GetSiteInstanceAsync error:

Error: System.ArgumentNullException: Value cannot be null. (Parameter 'resourceId')
   at Azure.Core.Argument.AssertNotNullOrEmpty(String value, String name)
   at Azure.Core.ResourceIdentifier..ctor(String resourceId)
   at Azure.ResourceManager.AppService.WebSiteInstanceStatusData.DeserializeWebSiteInstanceStatusData(JsonElement element)
   at Azure.ResourceManager.AppService.WebAppsRestOperations.GetInstanceInfoAsync(String subscriptionId, String resourceGroupName, String name, String instanceId, CancellationToken cancellationToken)
   at Azure.ResourceManager.AppService.SiteInstanceCollection.GetAsync(String instanceId, CancellationToken cancellationToken)
   at Azure.ResourceManager.AppService.WebSiteResource.GetSiteInstanceAsync(String instanceId, CancellationToken cancellationToken)
   at Submission#66.<<Initialize>>d__0.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)

Reproduction Steps

For multiple instances:

var appService = await resourceGroup.Value.GetWebSiteAsync(appServiceName);
var instances = appService.Value.GetSiteInstances();
foreach(var i in instances)
{
    Console.WriteLine($"{i.Data.Name} - {i.Data.State}");
}

Or for a single instance:

var appService = await resourceGroup.Value.GetWebSiteAsync(appServiceName);
var instance = await appService.Value.GetSiteInstanceAsync(instanceName);

Environment

.net 6.0.300

mwgustin avatar Jul 29 '22 16:07 mwgustin

Label prediction was below confidence level 0.6 for Model:ServiceLabels: 'ARM:0.48226207,App Services:0.18079154,Container Instances:0.029155515'

azure-sdk avatar Jul 29 '22 16:07 azure-sdk

A little more testing/research on this. It appears this may be app services on Windows ASPs... Linux ASPs seem to be returning instances fine.

mwgustin avatar Jul 29 '22 18:07 mwgustin

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

jsquire avatar Jul 29 '22 20:07 jsquire

Is this confirmed as a bug? I am trying something similar to get list of instances under a website. I am also getting the same exception related to empty URI.

byteblocks avatar Nov 27 '22 15:11 byteblocks

Hello @jsquire,

I am also affected by this bug and I was wondering if the team got back to you about this bug? These are the details I found when I investigated the issue:

My callstack is identical to the one posted by mwgustin and I noticed that the issue is being thrown from a URI created inside the DeserializeWebSiteInstanceStatusData method. To investigate the issue I called the API manually and got this result:

{
    "value": [{
            "id": "/subscriptions/ecc...",
            "name": "8f71...",
            "type": "Microsoft.Web/sites/instances",
            "location": "Canada Central",
            "properties": {
                "state": "UNKNOWN",
                "name": "8f71...",
                "siteInstanceName": "8f71...",
                "statusUrl": "",
                "detectorUrl": "https://redacted.scm.azurewebsites.net/detectors",
                "consoleUrl": "https://redacted.scm.azurewebsites.net/DebugConsole?instance=8f71...",
                "healthCheckUrl": null,
                "machineName": "pd1mdwk00003O",
                "containers": null
            }
        }, {

As you can see, there are 3 "types" of URL: an empty string, a valid URL and a null value. I looked at the decompiled code for the method (DeserializeWebSiteInstanceStatusData) where the exception is thrown and it appears that it does not handle the URLs correctly. More specifically this is the code which reads the statusUrl property:

image

As you can see, the code check for null but not empty strings. Empty strings are passed to the Uri constructor which throws the invalid URL exception reported by mwgustin.

Do you think this can be fixed quickly?

Thanks

I looked at the code (decompiled) for DeserializeWebSiteInstanceStatusData and it appears that it does not handle the URLs correctly. More specifically this is the code which reads the statusUrl property:

orck-adrouin avatar Jan 25 '23 21:01 orck-adrouin

Hi @orck-adrouin. Unfortunately, my role for this issue is just initial triage. I have no insight into its current state. Updates would need to be provided by the assigned engineer, @ArcturusZhang.

//cc: @xboxeer

jsquire avatar Jan 25 '23 21:01 jsquire

@ArcturusZhang Do you need more information to investigate this issue?

orck-adrouin avatar Feb 01 '23 19:02 orck-adrouin

Hi @jsquire. Same issue when getting instances information for a wep app service in Windows service plan.

Using Azure Resources Explorer web to get instances information, returns empty string for all instances in statusUrl property.

Inspecting code for DesearializeWebSiteInstanceStatusData method, in file WebSiteInstanceStatusData.Serialization.cs, at /sdk/websites/Azure.ResourceManager.AppService/src/Generated/Models/WebSiteInstanceStatusData.Serialization.cs, line 133: if (property0.NameEquals("statusUrl"u8)) { if (property0.Value.ValueKind == JsonValueKind.Null) { statusUrl = null; continue; } statusUrl = new Uri(property0.Value.GetString()); continue; } It is what @orck-adrouin has already commented, it checks if statusUrl is null, but does not check if it is empty string, and ends up using new Uri("") that throws exception with error System.UriFormatException: Invalid URI: The URI is empty.

Can it be fixed, please?

Thanks very much.

gejojimenez avatar Feb 15 '23 08:02 gejojimenez

Hi, any ETA for a patch ? I encounter the issue too and reading the conversation it looks like a simple fix.

nazbrok avatar Jun 23 '23 08:06 nazbrok

Will be fixed in the next release version

live1206 avatar Jun 27 '23 09:06 live1206

hi @live1206 We are blocking by this, Is there any plan to release a new version? thanks

Danieladu avatar Sep 06 '23 02:09 Danieladu

@live1206 So quick. thanks!

Danieladu avatar Sep 06 '23 05:09 Danieladu