[Archived] Code for hosting and starting up an ASP.NET Core application. Project moved to https://github.com/aspnet/Extensions and https://github.com/aspnet/AspNetCore
Apache License 2.0
552
stars
312
forks
source link
Don't hold onto the HttpContext in the HostingLogScope #1531
Multiple things capture the ExecutionContext, reduce the changes of improperly rooting the HttpContext when we only need a few properties from the request.
Intentional memory leak
using System.Threading;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
namespace WebApplication23
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
var cts = new CancellationTokenSource();
app.Run(async (context) =>
{
cts.Token.Register(() =>
{
});
await context.Response.WriteAsync("Hello World!");
});
}
}
}
This code will capture every HttpContext in the logging scope:
It's rooted by the scope which is being captured in the CancellationToken callback.
Intentional memory leak
This code will capture every HttpContext in the logging scope:
It's rooted by the scope which is being captured in the CancellationToken callback.
cc @benaadams