Skip to content

Make IHttpResponseStartFeature more forgiving #7779

@halter73

Description

@halter73

Today, if you call ResponseBodyPipe.GetMemory() to start writing the response body without first calling IHttpResponseStartFeature.StartAsync(), GetMemory() will throw on Kestrel because the possibly-async response OnStarting callbacks haven't gotten the chance to run and we don't want to block in GetMemory() to wait for them.

Instead, we should make the behavior more forgiving by having GetMemory() return memory leased directly from the memory pool instead of the response body PipeWriter. This would continue until the first call to FlushAsync(). At that point, the OnStarting callbacks would be called, the headers would be committed, and the data written to the memory leased directly to the pool would be copied to the response body PipeWriter.

This way, calling IHttpResponseStartFeature.StartAsync() improves efficiency by avoiding copies before the first flush, but not calling StartAsync() doesn't break the app.

@davidfowl @jkotalik @Tratcher @muratg

Metadata

Metadata

Assignees

Labels

DoneThis issue has been fixedarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-pipelinesAnything relating to exposing/using Pipes in ASP.NET Core

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions