Azure function (dotnet-isolated) fails to start with Grpc.Core.RpcException: StatusCode="Unavailable" - Mac M1

1.8k views Asked by At

I recently got a Mac M1, and in the process of setting up my machine for Azure Function(dotnet-isolated) development.

I followed below document, which worked perfectly well on my Windows 10 machine. https://learn.microsoft.com/en-us/azure/azure-functions/create-first-function-cli-csharp?tabs=azure-cli%2Cisolated-process

Below is the setup in Mac,

% func --version 4.0.4895

% dotnet --list-sdks 6.0.403 [/usr/local/share/dotnet/sdk]

% azure-functions-core-tools@4

% az --version azure-cli 2.42.0

core 2.42.0 telemetry 1.0.8

Dependencies: msal 1.20.0 azure-mgmt-resource 21.1.0b1

Once above installation is done, create a new function using following command

% func new --template "Http Trigger" --name MyHttpTrigger

and then when I tried to start the Function using % func start

I get following error .....

MyHttpTrigger: [GET,POST] http://localhost:7071/api/MyHttpTrigger
For detailed output, run func with --verbose flag.
[2022-11-30T09:21:10.868Z] Unhandled exception. Grpc.Core.RpcException: Status(StatusCode="Unavailable", Detail="Error starting gRPC call. HttpRequestException: An error occurred while sending the request. IOException: An HTTP/2 connection could not be established because the server did not complete the HTTP/2 handshake. IOException: Unable to write data to the transport connection: Broken pipe. SocketException: Broken pipe", DebugException="System.Net.Http.HttpRequestException: An error occurred while sending the request.
[2022-11-30T09:21:10.868Z]  ---> System.IO.IOException: An HTTP/2 connection could not be established because the server did not complete the HTTP/2 handshake.
[2022-11-30T09:21:10.868Z]  ---> System.IO.IOException: Unable to write data to the transport connection: Broken pipe.
[2022-11-30T09:21:10.868Z]  ---> System.Net.Sockets.SocketException (32): Broken pipe
[2022-11-30T09:21:10.868Z]    at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.CreateException(SocketError error, Boolean forAsyncThrow)

csproj

    <Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.8.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.7.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
  <ItemGroup>
    <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
  </ItemGroup>
</Project>

Porgram.cs

using Microsoft.Extensions.Hosting;
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.Build();
host.Run();

Function

using System.Net;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;

namespace LocalFunctionProj
{
    public class MyHttpTrigger
    {
        private readonly ILogger _logger;

        public MyHttpTrigger(ILoggerFactory loggerFactory)
        {
            _logger = loggerFactory.CreateLogger<MyHttpTrigger>();
        }

        [Function("MyHttpTrigger")]
        public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req)
        {
            _logger.LogInformation("C# HTTP trigger function processed a request.");

            var response = req.CreateResponse(HttpStatusCode.OK);
            response.Headers.Add("Content-Type", "text/plain; charset=utf-8");

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

            return response;
        }
    }
}

local.settings.json

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
    }
}

launchSettings.json

{
  "profiles": {
    "LocalFunctionProj": {
      "commandName": "Project",
      "commandLineArgs": "--port 7146",
      "launchBrowser": false
    }
  }
}

Any input on what I am missing here please?

2

There are 2 answers

0
TheImmortal On

I know this is late coming to the party, but, I recently hit this problem as well and it turned out to be a problem of order of invocation in my Program.cs. In short, I had the call to ConfigureFunctionsWorkerDefaults coming before ConfigureAppConfiguration. I beat my head against the wall for much longer than I'd like to admit on this one. Once I switched the invocation order, all was well. For example:

var host = new HostBuilder()
.ConfigureAppConfiguration(builder => builder.AddEnvironmentVariables())
.ConfigureFunctionsWorkerDefaults()
.Build();

Hopefully, this helps others.

1
Juliana Polo On

I got the same issue with an Azure Function with .NET 4.8 dotnet-isolated. After checking some blogs, I validated the firewall rules on Windows Defender Firewall and found a couple of rules for func.exe ( the executable file generated for the Azure Function) blocking the connection. After enabling this rules, I was able to execute the function without problems