Azure Functions runtime is unreachable

There are a few reasons why you may get this notification, shown in Figure 1 when you try to view your Function list in the Azure portal.  One such reason is that you have some kind of network restriction like VNET or Firewall that prevents the Azure Function host from accessing the Azure Storage Account on which your code exists.  So, check your endpoints which you have configured in the AzureWebJobsStorage and WEBSITE_CONTENTAZUREFILECONNECTIONSTRING application settings, and make sure there is nothing restricting the Function App host from access.

Here is an official list of things which can cause this notification to occur. I didn’t find this specific scenario in that article.

image

Figure 1 – Azure Functions runtime is unreachable

That isn’t the possible cause I want to focus on in this article though.  Instead I want to mention one which may be a little harder to find, one of those needle in a haystack kind of things, that shouldn’t happen, but sometimes does.  In short, on a rare occasion a file named App_Offline.htm might end up in your site/wwwroot/ directory which results in the Function App going offline.  I want to show you how to see if this is the case.  Most simply, you can just access KUDU and look at the files via the Debug console, but what fun is that, clickidy-click, keep it simple results in obfuscating the complexities of what happens behind the scenes and limits learning and technical skill progression.  But, if you are in a hurry, just look at KUDU and you would find what you see in Figure 2, remember that having that file in that directory results in the notification seen in Figure 1.

image

Figure 2 – Azure Functions runtime is unreachable, App_Offline.htm, KUDU

Let’s use Azure CLI to call some REST APIs which flow through the Azure Resource Provider and interpret those results.  The first action is to call the REST API like the following which results in that shown in Figure 3 if the Azure Function App is Offline for some reason.  (NOTE:  I break the syntax into multiple lines for presentation reasons, it should all be on a single line or use proper line break syntax)

az rest –url
"https://management.azure.com/subscriptions/<subscriptionId>/resourceGroups/<resoureGroup>
/providers/Microsoft.Web/sites/<functionName>/host/default/properties/status?api-version=2018-11-01"

image

Figure 3 – Azure Functions runtime is unreachable, check Function App Host properties

Well, that tells you something you already knew, the state can also be Running or Stopped.  There may be others but those are what I saw while testing this out.  Next, to check and see if there exists a App_Offline.htm in your site/wwwroot/ directory, again you can use Azure CLI to check the contents of that directory.  A consumption hosted Azure Function App stores the contents in a Azure Files.  You can use the following command to check for its existence.  The result of that command would look similar to Figure 4.

az storage file exists --account-name <> --path site/wwwroot/App_Offline.htm --share-name <> --account-key nK5c0fY...Svy+3Q==

image

Figure 4 – Azure Functions runtime is unreachable, check Azure Files for the existence of a specific filename

This information may be helpful in finding the values to successfully execute that command.

  • –account-name: you will find this in the value of the WEBSITE_CONTENTAZUREFILECONNECTIONSTRING application setting after the AccountName= syntax.  The value is the name of the Azure Storage Account where the Azure Files share exists.  This is usually the same as AzureWebJobsStorage, but not always.
  • –share-name: this is the value for the WEBSITE_CONTENTSHARE application setting
  • –account-key: you will find this in the same place as the –account-key, but after the AccountKey= syntax

Once I removed the file, I did it via KUDU because it was the quickest, but I could have done it using Azure CLI, anyway, once I removed the App_Offline.htm the status showed as Running and all was good.  See Figure 5.

image

Figure 5 – Azure Functions runtime is unreachable, running

Finally, if the Function App is stopped and I attempted the az rest command I received the following:

“Message”:”Encountered an error (Forbidden)

I could only see stopped when I ran az functionapp show –n <functionApp> –g <resourceGroup>

image