Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

When HttpResponse.Body is replaced, the replacement is used for future requests #1028

Closed
muratg opened this issue Aug 4, 2016 · 2 comments
Closed

Comments

@muratg
Copy link
Contributor

muratg commented Aug 4, 2016

Copied from #940 to consider this for 1.0.1.

This is a contrived example to illustrate the point:

app.Use(next => context =>
{
    if (context.Response.Body is MemoryStream)
    {
        throw new Exception("Wrong stream type in context.Response.Body");
    }

    context.Response.Body = new MemoryStream();

    return context.Response.WriteAsync("Hello, world!");
});

Run the application and browse to it. The first request returns nothing (content was written to the MemoryStream). Subsequent requests will hit the Exception.

The real-world case is when the Body stream is decorated for a given request. The decorator stream will be re-used for a subsequent request, which could result in re-decorating the stream, and ultimately produce a long chain of decorators.

It appears that Kestrel is trying to be efficient by re-using its underlying Stream instances. But the reusable instances are being replaced, with unintended consequences for future requests.

@cesarblum
Copy link
Contributor

@muratg Should I close this? Or are we waiting for something before closing 1.0.1 issues?

@muratg
Copy link
Contributor Author

muratg commented Aug 24, 2016

@CesarBS Sure, make sure to update the label to done.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants