17

I have a dotnet 5 function app that I've been building and deploying from a devops pipeline for a couple of weeks.

Following the most recent release, I see the following error in App Insights:

Exception type System.TimeoutException Exception message The operation has timed out. LogLevel Error prop__{OriginalFormat} Failed to start a new language worker for runtime: dotnet-isolated. Category Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcFunctionInvocationDispatcher System.TimeoutException: The operation has timed out. at Microsoft.Azure.WebJobs.Script.Grpc.GrpcWorkerChannel.StartWorkerProcessAsync()

csproj file:

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
    <Nullable>enable</Nullable>
    <UserSecretsId>4f786da6-0d47-4ccc-b343-638a6e34e1cf</UserSecretsId>
  </PropertyGroup>

  <ItemGroup>
    <None Remove="local.settings.json" />
  </ItemGroup>

  <ItemGroup>
    <Content Include="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </Content>
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.2.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Abstractions" Version="1.0.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage" Version="4.0.4" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.0.3" />
    <PackageReference Include="Microsoft.Azure.Services.AppAuthentication" Version="1.6.1" />
    <PackageReference Include="Microsoft.Data.SqlClient" Version="3.0.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="5.0.0" />
    <PackageReference Include="NSwag.AspNetCore" Version="13.11.1" />
    <PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
    <PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="3.1.0" />
    <PackageReference Include="Serilog.Sinks.MSSqlServer" Version="5.6.0" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\infrastructure\SmsRouter.GovNotify\SmsRouter.GovNotify.csproj" />
    <ProjectReference Include="..\SmsRouter.Infrastructure\SmsRouter.EntityFramework.csproj" />
    <ProjectReference Include="..\SmsRouter.Utrn\SmsRouter.Utrn.csproj" />
  </ItemGroup>

  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>

</Project>

host.json:

{
  "version": "2.0"
}

Function App Configuration:

[
  {
    "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
    "value": "<my key is here>",
    "slotSetting": true
  },
  {
    "name": "AzureWebJobsStorage",
    "value": "DefaultEndpointsProtocol=https;AccountName=storesmsroutermsdn;AccountKey=<my key is here>;EndpointSuffix=core.windows.net",
    "slotSetting": false
  },
  {
    "name": "FUNCTIONS_EXTENSION_VERSION",
    "value": "~3",
    "slotSetting": false
  },
  {
    "name": "FUNCTIONS_WORKER_RUNTIME",
    "value": "dotnet-isolated",
    "slotSetting": false
  },
  {
    "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
    "value": "DefaultEndpointsProtocol=https;AccountName=storesmsroutermsdn;AccountKey=<my key is here>;EndpointSuffix=core.windows.net",
    "slotSetting": false
  },
  {
    "name": "WEBSITE_CONTENTSHARE",
    "value": "func-smsrouter-msdn-01b300",
    "slotSetting": false
  },
  {
    "name": "WEBSITE_ENABLE_SYNC_UPDATE_SITE",
    "value": "true",
    "slotSetting": false
  },
  {
    "name": "WEBSITE_RUN_FROM_PACKAGE",
    "value": "1",
    "slotSetting": false
  }
]

Function Definition

[Function("HttpExample")]
    public static HttpResponseData Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req,
        FunctionContext executionContext)
    {
        var response = req.CreateResponse(HttpStatusCode.OK);
        response.Headers.Add("Content-Type", "text/plain; charset=utf-8");

        response.WriteString("Welcome to Azure Functions!");

        return response;
    }

Has anyone else run into this problem?

Note: I have now created a support ticket for this via the Azure Portal - the id is 2106280050000196. Github issue here

Edit: Following the suggestion from @Kaylan, I used Azure CLI to create a new function app with --runtime dotnet-isolated param. I then deployed my functions into this (using devops pipeline with the Deploy Azure Function task) but I'm afraid I continue to see the same error.

I've also tried deploying to a fixed app service plan (rather than consumption) but continued to hit the same problem.

Rob Bowman
  • 7,632
  • 22
  • 93
  • 200
  • Could you please post your host.json file and .csproj so we can look at the configuration and dependencies? – Kalyan Chanumolu-MSFT Jun 25 '21 at 06:56
  • @KalyanChanumolu-MSFT please see updated question with the request file content – Rob Bowman Jun 25 '21 at 07:38
  • Could you please add ExtensionBundle configuration to host.json and try? { "version": "2.0", "extensionBundle": { "id": "Microsoft.Azure.Functions.ExtensionBundle", "version": "[2.*, 3.0.0)" } } – Kalyan Chanumolu-MSFT Jun 25 '21 at 08:10
  • Also, please upgrade the Microsoft.Azure.Functions.Worker to 1.3.0 – Kalyan Chanumolu-MSFT Jun 25 '21 at 08:13
  • I'm running into the same issue locally. I've tried the above suggestions from @KalyanChanumolu-MSFT without any luck. I've also tried updating azure-functions-core-tools to 3.0.3568 and even the preview 4.0.3594 without any luck. Might be related to the runtime holding onto a port, as including a --port parameter seems to allow the process to start sometimes. – idolos Jun 25 '21 at 11:18
  • Running into this issue during local debugging is a known issue. https://github.com/Azure/azure-functions-dotnet-worker/issues/434 You shouldn't ideally see this with a published app. – Kalyan Chanumolu-MSFT Jun 25 '21 at 12:33
  • @KalyanChanumolu-MSFT I made the changes you suggested, and ran through the build and release pipelines. Now, if I click "Functions" (the Icon above App Keys) in the Azure Portal, I get "No results." I've checked all of the logs I can find in App Insights and Kudu but there's no sign of any errors since the most recent release – Rob Bowman Jun 25 '21 at 19:51
  • @KalyanChanumolu-MSFT sorry my explanation wasn't clear. The change has not worked. Although there are no longer any errors in the logs - there is no sign of the functions in the app. If I issue a GET to what should be the URL of the http triggered function then I receive a 404. – Rob Bowman Jun 26 '21 at 06:21

9 Answers9

9

I was just dealing with the same problem. I finally fixed it by adding .ConfigureFunctionsWorkerDefaults() to my Program.cs file. I had removed it by accident.

I guess what I'm saying is, make sure you have .ConfigureFunctionsWorkerDefaults() in your Program.cs file. Here's an example:

using DataApi.AzureFunctions.Throttled;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;

var host = new HostBuilder()
    .ConfigureAppConfiguration(configBuilder => configBuilder.AddEnvironmentVariables())
    .ConfigureFunctionsWorkerDefaults() // <---- OMITTING THIS IS ONE POSSIBLE CAUSE OF THE ERROR "Failed to start a new language worker for runtime: dotnet-isolated."
    .ConfigureServices(Startup.Configure)
    .UseDefaultServiceProvider((_, options) =>
    {
        options.ValidateScopes = true;
        options.ValidateOnBuild = true;
    })
    .Build();

await host.RunAsync();

Benrobot
  • 2,630
  • 1
  • 21
  • 24
4

Whatever you do, with Azure App Services and Function Apps, always, always, triple check you have all your Configuration Settings complete and typo-free. A missing or misspelled setting can cause start up and dependency injection problems with cryptic messages like this one. Also, if you are using staging slots, make sure they either also have all their configuration settings correct, or keep the staging slots stopped.

Gedeon
  • 742
  • 9
  • 13
3

When you make some change that utterly destroy the app before it even starts, and have no idea what is causing this disaster.


If your function app is on Linux

I don't know, good luck? You can see logs of processes from Kudu when the app starts, which might help.


If your function app is on Windows

  • Open Kudu Console (Your Functions App > Advanced Tools > Go)
  • From the top menus, Debug Console > CMD
  • Navigate and open \home\LogFiles\eventlog.xml
    • note that the console opens at \home
  • Scroll to the bottom to see the latest error

If the file is huge and you have no idea which one is your error, you can delete the file, then restart the functions app. New logs will be populated.

Madushan
  • 6,977
  • 31
  • 79
1

I got this propblem because I'd moved form a "normal" dotnet service and needed to tweak the FUNCTIONS_WORKER_RUNTIME from dotnet to dotnet-isolated:

local.settings.json

{
  "IsEncrypted": false,
  "Values": {

    "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
    ....

  }
}
Liam
  • 27,717
  • 28
  • 128
  • 190
1

I have tried multiple things for this issue, but what solved my problem is cleaning existing storage account for function app. I got that information from here https://github.com/Azure/azure-functions-dotnet-worker/issues/434#issuecomment-973408898

Ajay Kumar
  • 11
  • 3
0

Please make the below changes to your host.json file to include extensionBundle

{
  "version": "2.0",
    "extensionBundle": {
      "id": "Microsoft.Azure.Functions.ExtensionBundle",
      "version": "[2.*, 3.0.0)"
    }
  }
}

Upgrade to Microsoft.Azure.Functions.Worker version 1.3.0 or higher

Install-Package Microsoft.Azure.Functions.Worker -Version 1.3.0

Ensure that the appropriate runtime is specified while creating the Function App.

az functionapp create --consumption-plan-location westus --name <FunctionAppName> --resource-group <ResourceGroupName> --runtime dotnet-isolated --runtime-version 5.0 --functions-version 3 --storage-account <StorageAccountName>
  • 1
    Please see comment for question. I've also noticed that after making these changes, I can no longer run the app in the local emulator because it gives the following error: "No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code" – Rob Bowman Jun 26 '21 at 06:30
  • However, if I remove the changes from host.json (leaving just "version": "2.0") then the app will run in the local emulator. I'm just going to try the same when deployed to Azure... – Rob Bowman Jun 26 '21 at 06:38
  • Could you please post your function definition? Is it only the HTTP triggered endpoints you have an issue with? Here is a sample [Function("GetHeartBeatEndPoint")] public HttpResponseData GetHeartBeatEndPoint([HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequestData req, FunctionContext executionContext) {} – Kalyan Chanumolu-MSFT Jun 26 '21 at 06:51
  • Sorry, I have to leave now but I will post the function definition before the end of the day – Rob Bowman Jun 26 '21 at 06:54
  • Hi Kalyan, please find my function definition attached to main question – Rob Bowman Jun 26 '21 at 15:52
  • I was able to repro this issue while deploying my app to an existing function app created via the portal. Currently you can create a function app with dotnet-isolated runtime using the Azure CLI only. Please ensure your devops pipeline is specifying the appropriate runtime in the command. I have updated the answer to include a sample – Kalyan Chanumolu-MSFT Jun 28 '21 at 07:55
  • I deleted the function app then re-created using the az functionapp create command from a Cloud Shell window. I then re deployed my function app package (zip) into the new function app using the "Deploy Azure Function App" DevOps task. I am now able to call the "Welcome to Azure Functions" http endpoint but if I call the "real" http triggered function I get the original error along with "Failed to start a new language worker for runtime: dotnet-isolated." Both function are in the same function app so I'm surprised one works – Rob Bowman Jun 28 '21 at 09:13
  • Am sorry you are experiencing this problem. This is strange indeed. Is there a way you can upload the solution to a github repo so that i can take a look? – Kalyan Chanumolu-MSFT Jun 28 '21 at 09:39
  • Kalyan, can you please email me rob@biztalkers.com and I'll send you credentials for the repo – Rob Bowman Jun 28 '21 at 09:41
0

I just ran a NuGet package update for:

  • Microsoft.Azure.Functions.Worker v1.3.0 → v1.4.0
  • Microsoft.Azure.Functions.Worker.sdk v1.0.3 → v1.0.4

This seems to have solved the problem.

H. Pauwelyn
  • 13,575
  • 26
  • 81
  • 144
Rob Bowman
  • 7,632
  • 22
  • 93
  • 200
  • Although updating the nuget package in our "Development" azure subscription seemed to fix the problem - this was a false dawn :( The same code has been deployed to our "Test" subscription. This is giving the same grpc timeout error - although the function in the "Development" subscription continues to work – Rob Bowman Aug 19 '21 at 14:30
  • Have you created your function app correctly on your test subscription: az functionapp create --consumption-plan-location westus --name --resource-group --runtime dotnet-isolated --runtime-version 5.0 --functions-version 3 --storage-account ? – mslot Aug 20 '21 at 14:12
  • @mslot the function app was created using the same ARM template as that for the "Dev" environment - they have different Parameters files. The function app code is deployed into the app using the DevOps Release Pipeline Task "Deploy Azure Function App" version "1.*. The only parameters used for this are Azure subscription, App Type of "Function App on Windows", App Name and the zip containing the app code - published by the DevOps build pipeline – Rob Bowman Aug 20 '21 at 14:19
0

The reason that I got this error was due to a missing DBContext constructor. The error message seems entirely irrelevant and a complete red herring so hopefully this will help somebody who has the same issue.

I am using Entity Framework Core for MySQL. For some reason EF does not work if the constructor which accepts a DbContextOptions parameter is present. Each time I add a migration I comment it out. This last time I forgot to uncomment it and published the Function App to Azure. When I attempted to run the function I got this same error.

public class MyContext: DbContext
    {
        // while doing ef migrations we need to comment out this constructor below
       
        public MyContext(DbContextOptions<MyContext> options) : base(options)
        {
        }
   
        public MyContext()
        {

        }

I

zeiddev
  • 662
  • 7
  • 23
0

I had the same issue, and any attempts to change Microsoft.Azure.Functions.Worker version as mainly suggested in most similar solution doesn't bring success.

The main root cause is timeout. And finally i found a solution. In my case

 .ConfigureServices(Startup.Configure)

takes a couple of second, due to the specific of the project, auditing etc. Changes in my Startup.Configure to run without delay and as much as possible faster. Bring positive result. Problem disappears on all versions of worker