Description
AllowSynchronousIO disabled in all servers
AllowSynchronousIO is a option in each server that enables or disables sync IO APIs like HttpReqeuest.Body.Read, HttpResponse.Body.Write, Stream.Flush, etc.. These APIs have long been a source of thread starvation and application hangs. Starting in 3.0.0-preview3 these are disabled by default.
Affected servers:
- Kestrel
- HttpSys
- IIS in-process
- TestServer
Expect errors similar to:
Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead.
Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead.
Synchronous operations are disallowed. Call FlushAsync or set AllowSynchronousIO to true instead.
Each server has a AllowSynchronousIO option that controls this behavior and the default for all of them is now false.
The behavior can also be overridden on a per request basis as a temporary mitigation.
var syncIOFeature = HttpContext.Features.Get<IHttpBodyControlFeature>();
if (syncIOFeature != null)
{
syncIOFeature.AllowSynchronousIO = true;
}
If you have trouble with TextWriters or other streams calling sync APIs in Dispose, call the new DisposeAsync API instead.
See dotnet/aspnetcore#7644 for discussion.
Version introduced
3.0
Old behavior
HttpReqeuest.Body.Read, HttpResponse.Body.Write, Stream.Flush were allowed by default.
New behavior
These synchronous APIs are disallowed by default:
Expect errors similar to:
Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead.
Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead.
Synchronous operations are disallowed. Call FlushAsync or set AllowSynchronousIO to true instead.
Reason for change
These APIs have long been a source of thread starvation and application hangs. Starting in 3.0.0-preview3 these are disabled by default.
Recommended action
Use the async versions of the methods, also the behavior can also be overridden on a per request basis as a temporary mitigation.
var syncIOFeature = HttpContext.Features.Get<IHttpBodyControlFeature>();
if (syncIOFeature != null)
{
syncIOFeature.AllowSynchronousIO = true;
}
Category
- ASP.NET Core
Affected APIs
HttpRequest.Body.Read
HttpResponse.Body.Flush
HttpResponse.Body.Write
Issue metadata
- Issue type: breaking-change