Skip to content

BodyWriter polyfill doesn't flush, causes truncation #11305

Closed
@Tratcher

Description

@Tratcher

#11268 identified a truncation issue with the HttpContext.Response.BodyWriter polyfill logic.

The BodyWriter polyfill automatically creates a pipe wrapped around the stream. If you use this pipe to call GetMemory and Advance but do not call FlushAsync, this data is not flushed to the underlying stream. When the request unwinds the pipe will eventually be completed by the OnCompleted event, but it's too late to flush the data as the response has already been disposed.

This is different behavior from any server that does expose pipes (Kestrel) where any data in the pipe is automatically flushed by the server when it completes the pipe.

Proposal: This polyfill should have been implemented as middleware that could auto-flush the pipe at the end of the request.

Note that polyfill middleware would also need to intercept CompleteAsync and flush in that case as well.

Counter proposal: The app is always required to call FlushAsync.

@davidfowl @JamesNK

Metadata

Metadata

Assignees

Labels

DoneThis issue has been fixedapi-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsbugThis issue describes a behavior which is not expected - a bug.feature-http-abstractions

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions