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

Dispose IDisposable objects in ObjectResult, FileStreamResult and others in exceptional cases #1331

Closed
kichalla opened this issue Oct 10, 2014 · 3 comments
Assignees
Labels
Milestone

Comments

@kichalla
Copy link
Member

Scenario:
Users typically do the following in Web API. Here the expectation is that the file stream would be closed after the content from the file has been read and written out.

public HttpResponseMessage DownloadFile()
{
    var response = new HttpResponseMessage();
    response.Content = new StreamContent(File.OpenRead(@"C:\Images\image1.jpg"));
    response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
    response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
    return response;
}
@kichalla kichalla self-assigned this Oct 10, 2014
@kichalla kichalla added this to the 6.0.0-beta1 milestone Oct 10, 2014
kichalla added a commit that referenced this issue Oct 11, 2014
kichalla added a commit that referenced this issue Oct 11, 2014
kichalla added a commit that referenced this issue Oct 14, 2014
kichalla added a commit that referenced this issue Oct 14, 2014
@kichalla
Copy link
Member Author

Reactivating this bug as we also need to handle the scenario where in case of exceptions we need to make sure to dispose HttpResponseMessage

@kichalla kichalla reopened this Oct 15, 2014
@kichalla kichalla removed this from the 6.0.0-beta1 milestone Oct 15, 2014
@rynowak
Copy link
Member

rynowak commented Oct 15, 2014

It's also possible for a filter to change the result and 'hide' the response we created. We need a robust solution for this.

@danroth27 danroth27 added this to the 6.0.0-beta1 milestone Oct 15, 2014
@rynowak rynowak modified the milestones: 6.0.0-rc1, 6.0.0-beta1 Oct 17, 2014
@kichalla kichalla changed the title Dispose HttpResponseMessage once its written out in HttpResponseMessageOutputFormatter Dispose HttpResponseMessage in additional scenarios like unhandled exceptions etc. Oct 20, 2014
@danroth27 danroth27 modified the milestones: 6.0.0-rc1, 6.0.0-beta2 Oct 20, 2014
@yishaigalatzer yishaigalatzer modified the milestones: 6.0.0-rc1, 6.0.0-beta2 Dec 12, 2014
@yishaigalatzer yishaigalatzer modified the milestones: 6.0.0-rc1, 6.0.0-beta3 Jan 12, 2015
@yishaigalatzer yishaigalatzer changed the title Dispose HttpResponseMessage in additional scenarios like unhandled exceptions etc. Dispose IDisposable objects in ObjectResult, FileStreamResult and others in exceptional cases Feb 4, 2015
@yishaigalatzer
Copy link
Contributor

Strawman design:

Include all objects that needs disposing on the Response/Request and dispose them with the request unwinds (or when exiting MVC).

ObjectResult, can upon setting the Value can register the type for disposal if it implement IDisposable, similarly FileStreamResult can do the same.

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

No branches or pull requests

5 participants