9

I am building a HTTPTriggered Azure Function, targeting netcoreapp3.0, that is running a GraphQL .NET server. GraphQL .NET requires that AllowSynchronousIO is set to true, but I can't figure out how to do that for a Azure Function. I have tried implementing my own Startup class that extends FunctionsStartup and added the below code in the Configure method with no luck.

builder.Services
    .AddOptions<KestrelServerOptions>()
    .Configure<IConfiguration>((settings, configuration) =>
    {
        settings.AllowSynchronousIO = true;
        configuration.Bind(settings);
    });

The error message I get is:

An unhandled host error has occurred.

Microsoft.AspNetCore.Server.Kestrel.Core: Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead.

Any help would be greatly appreciated!

Ganhammar
  • 1,871
  • 1
  • 16
  • 29

2 Answers2

14

Setting the environment variable FUNCTIONS_V2_COMPATIBILITY_MODE to true seems to solve the issue, see https://github.com/Azure/azure-functions-host/pull/5286.

Ganhammar
  • 1,871
  • 1
  • 16
  • 29
1

Why error:

Synchronous IO not enabled

How to fix:

Edit the "local.settings.json" file in your project root folder to look like this. "FUNCTIONS_V2_COMPATIBILITY_MODE": "true"

   {
      "IsEncrypted": false,
      "Values": {
        "FUNCTIONS_WORKER_RUNTIME": "dotnet",
        //Enable Synchronous IO
        "FUNCTIONS_V2_COMPATIBILITY_MODE": "true"
      },
      "Host": {
        "LocalHttpPort": 7071,
        "CORS": "*",
        "CORSCredentials": false
      }
    }
user160357
  • 865
  • 10
  • 14