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

ServiceProvider.Dispose should not stop if a bad service throws on Dispose #506

Closed
jdom opened this issue Mar 16, 2017 · 6 comments
Closed

Comments

@jdom
Copy link

jdom commented Mar 16, 2017

Currently if there is one badly implemented service that throws on Dispose, then because there is no try/catch in ServiceProvider.Dispose() when enumerating, the whole Dispose stops and bubbles up.

Ideally Dispose on every service implementation shouldn't throw, but the ServiceProvider could be a little more resilient against this typical issue and try to clean up as much as possible, and then bubble up the exception (or aggregate exception?). Even if being a little careful, it can sometimes be easy to miss these issue when implementing a service, especially since the Dispose order is not necessarily intuitive (see #463).

Thoughts?

@davidfowl
Copy link
Member

We could but you could fix your code to not throw in dispose. I'm not even sure what state the object is in at that point...

@benaadams
Copy link
Contributor

https://msdn.microsoft.com/en-us/library/fs2xkftw(v=vs.110).aspx

a Dispose method should be callable multiple times without throwing an exception

Not sure throwing when called once is a valid corner case 😉

@jdom
Copy link
Author

jdom commented Mar 16, 2017

Yup, I already fixed my code. Still thought that ServiceProvider should be a little bit more resilient since it is meant to glue together completely decoupled object graphs. So one bad apple in a big system shouldn't stop the entire container to stop disposing all the other correctly built services.
Just my 2 cents.

@Eilon
Copy link
Member

Eilon commented Mar 19, 2017

My gut says that if a service throws during dispose, that all bets are off. How is the application intending to continue after such a failure? (This is assuming it isn't during shutdown, in which case I think none of this matters anyway.)

@Antaris
Copy link

Antaris commented Mar 21, 2017

In the case of responsibility - I'd argue that it is not the service providers responsibility to handle faulty dispose logic.

@muratg
Copy link

muratg commented Apr 14, 2017

Agreed with @Eilon, closing this one.

@muratg muratg closed this as completed Apr 14, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants