Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Servers, nginx and Docker

Azure Functions returns InternalServerError from the host runtime

Your error

Encountered an error (InternalServerError) from host runtime.2 more lines it can show

Fix it fast

Most common cause, 1 of 3

AzureWebJobsStorage is missing, wrong or points at a deleted account

Put a current connection string back into AzureWebJobsStorage, then restart.

Fix
conn=$(az storage account show-connection-string --name mystorageacct --resource-group my-rg --query connectionString -o tsv)
az functionapp config appsettings set --name my-func-app --resource-group my-rg --settings AzureWebJobsStorage="$conn"
az functionapp restart --name my-func-app --resource-group my-rg
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Encountered an error (InternalServerError) from host runtime shows up when the Functions host behind the app is not running, so listKeys, deployments and portal calls fail. On runtime 4.x Microsoft names lost storage access as the usual reason: a missing or stale AzureWebJobsStorage, a storage firewall or Shared Key block, or ten unreadable host.snapshot backups. Fix storage, then restart.

  • Applies to Azure Functions runtime 4.x, Azure CLI 2.93 (az functionapp, az storage)
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

List the app settings and look for AzureWebJobsStorage. Missing or empty points to cause 1; a value that looks right sends you to the storage account itself (cause 2) and then to its secrets container (cause 3).

Run this first
az functionapp config appsettings list --name my-func-app --resource-group my-rg --query "[?name=='AzureWebJobsStorage']"

Then find the line you see in this list and open its fix:

  1. 1AzureWebJobsStorage is missing, wrong or points at a deleted accountThe query returns an empty list, or the account named in the connection string no longer exists or had its keys rotated
  2. 2The storage account refuses the app: firewall rules or Shared Key turned offThe connection string is valid, but the account's network default action is Deny or allowSharedKeyAccess is false
  3. 3Ten unreadable host.snapshot key backups block the secrets repositoryDiagnose and solve problems shows AZFD0007, or the azure-webjobs-secrets container holds a pile of host.snapshot.<date>.json files for this app

What does the error look like?

  • Encountered an error (InternalServerError) from host runtime.
  • Error: Azure Functions Runtime is unreachable. Click here for details on storage configuration.
  • AZFD0007: Repository has more than 10 nondecryptable secrets backups

Cause 1 of 3

AzureWebJobsStorage is missing, wrong or points at a deleted account

You seeThe query returns an empty list, or the account named in the connection string no longer exists or had its keys rotated

Check

Microsoft's troubleshooting page says the Functions runtime cannot start once the app loses its storage account, and reports in Azure-Functions issue 1657 cleared after AzureWebJobsStorage was set again. Deployment slots and Resource Manager scripts are the usual way the setting gets deleted or overwritten. Regenerated storage keys leave an old string behind, and on Consumption or Elastic Premium plans WEBSITE_CONTENTAZUREFILECONNECTIONSTRING needs the same care.

Check
az storage account show-connection-string --name mystorageacct --resource-group my-rg

Fix

Put a current connection string back into AzureWebJobsStorage, then restart. If the account was deleted, create a new one, set the string and redeploy your code, since the old package is gone with it.

Fix
conn=$(az storage account show-connection-string --name mystorageacct --resource-group my-rg --query connectionString -o tsv)
az functionapp config appsettings set --name my-func-app --resource-group my-rg --settings AzureWebJobsStorage="$conn"
az functionapp restart --name my-func-app --resource-group my-rg

Verify

The portal lists your functions again, and the listKeys step in the template completes.

Verify
az functionapp keys list --name my-func-app --resource-group my-rg

Confirmed by learn.microsoft.com

Did this fix it?

Cause 2 of 3

The storage account refuses the app: firewall rules or Shared Key turned off

You seeThe connection string is valid, but the account's network default action is Deny or allowSharedKeyAccess is false

Check

Microsoft lists a storage firewall that does not admit the function app, an App Service Environment without the right network rules, and Shared Key authorization switched off as reasons the host loses its storage. A key-based connection string cannot work while Shared Key is disabled.

Check
az storage account show --name mystorageacct --resource-group my-rg --query "{sharedKey:allowSharedKeyAccess, network:networkRuleSet.defaultAction}"

Fix

Allow the function app's traffic through the storage firewall (or its virtual network), and switch Shared Key back on while the app still authenticates with a key.

Fix
az storage account update --name mystorageacct --resource-group my-rg --allow-shared-key-access true
az functionapp restart --name my-func-app --resource-group my-rg

Verify

sharedKey prints true or null (both permit Shared Key), and the host answers the keys request without the 500 error.

Verify
az functionapp keys list --name my-func-app --resource-group my-rg

Confirmed by learn.microsoft.com

Did this fix it?

Cause 3 of 3

Ten unreadable host.snapshot key backups block the secrets repository

You seeDiagnose and solve problems shows AZFD0007, or the azure-webjobs-secrets container holds a pile of host.snapshot.<date>.json files for this app

Check

The host keeps its access keys in an encrypted file in the azure-webjobs-secrets container. Each time it cannot decrypt that file it writes a host.snapshot backup and starts fresh; at ten backups it gives up and the app may not start. Recreating an app with the same name on the same storage account, a changed decryption key and lifecycle policies all lead here.

Check
az storage blob list --account-name mystorageacct --container-name azure-webjobs-secrets --prefix my-func-app/ --query "[].name" -o tsv --auth-mode login

Fix

Delete the snapshot backups for this app only, then restart so the host has room to regenerate its key file. Since the old file could not be decrypted, read the keys again afterwards and update any caller that stored them.

Fix
az storage blob delete-batch --account-name mystorageacct --source azure-webjobs-secrets --pattern "my-func-app/host.snapshot.*" --auth-mode login
az functionapp restart --name my-func-app --resource-group my-rg

Verify

The snapshot list is empty or short, AZFD0007 no longer appears, and the keys request succeeds.

Verify
az functionapp keys list --name my-func-app --resource-group my-rg

Confirmed by learn.microsoft.com

Did this fix it?

How do I stop it coming back?

  • Give each function app its own storage account, or at least never reuse an app name on a shared account.
  • Never tick slot setting on AzureWebJobsStorage, and include it in every template that creates the app, since the host needs it valid from creation.
  • Before enabling the storage firewall or disabling Shared Key on an account, list every function app whose AzureWebJobsStorage points at it.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: Raheeb.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.