2

Im using Net Core 3.1 web api and I need to set AllowSynchronousIO = true. I have seen 2 differents ways to do it:

Per Server (affects all endpoints)

services.Configure<KestrelServerOptions>(options =>
{
     options.AllowSynchronousIO = true;
});

Or per Endpoint (inside a Controller's method):

var syncIOFeature = HttpContext.Features.Get<IHttpBodyControlFeature>();
if (syncIOFeature != null)
{
    syncIOFeature.AllowSynchronousIO = true;
}

Question: if I set AllowSynchronousIO=true per server all my endpoints are Synchronous? Is there a performance issue to set AllowSynchronousIO=true per Server VS per Endpoint? Whitch is better? Or it's just the same.

satellite satellite
  • 893
  • 2
  • 10
  • 27
  • Does this answer your question? [Buffered Stream - Synchronous operations are disallowed in ASP.NET Core 3.0](https://stackoverflow.com/questions/60984239/buffered-stream-synchronous-operations-are-disallowed-in-asp-net-core-3-0) – Lukasz Szczygielek Jan 22 '21 at 17:50
  • [AllowSynchronousIO disabled in all servers](https://github.com/dotnet/aspnetcore/issues/7644) – Pavel Anikhouski Jan 22 '21 at 18:14
  • Thanks for the links, I still with my doubt, maybe I'm missing something from them. I wanna know what is better option to use AllowSynchronousIO=true, used per Server or per Endpoint, and why. Thanks. – satellite satellite Jan 22 '21 at 18:29

1 Answers1

3

Because the aspnet core team took an opinionated approach that could cause their consumers pain in changing the default behavior to AllowSynchronousIO = false, I would recommend the IHttpBodyControlFeature (per endpoint) methodology to conform more closely to Microsoft's recommendation by limiting the scope of overriding the default. You can see a discussion around why they changed the default behavior here that explains it better than I can.

Additionally, I just ran into the issue using the global approach where we configured the KestrelServerOptions and it worked locally, but not when deployed because we additionally needed to configure the IISServerOptions. There a post on that here. This could be another reason to use the IHttpBodyControlFeature.

mheskamp
  • 74
  • 6