Closed erizzo closed 6 years ago
Hi @erizzo, Yup that sounds fun. Regarding the dispose mechanism, I don't think I can add anything more to it than throwing an Exception if someone tries to use a disposed CacheManager instance. This is already the "guard" check to prevent issues with disposed dependencies, which might occur later and might be even more verbose.
Dispose is a standard mechanism in .NET. and CacheManager just implements IDisposable so that resources or connections to cache servers can be closed etc.
If cacheManagerInstance.Dispose()
was invoked (manually or via a using statement or DI), an internal flag will be set which indicates that the instance cannot be used anymore. This flag gets checked on any method call and if it is set, the exception will be thrown.
And there is no way to re-initialize a disposed instance. All that's by design and how disposable is supposed to work I think ;)
This means that you might have a scenario in your code which references and uses a disposed instance.
First of all, you should figure out why the instance gets disposed.
I guess you never actually manually invoke Dispose
or put a using
around the instance?
Hint: If you have a website with DI, the DI system might dispose all singletons on app shutdown/crash.
/closeing for now, let me know if think I can assist or if you have a project to reproduce the behavior
In an app using CacheManager, deployed in Azure, we're occasionally seeing exceptions like this:
When it happens, we see hundreds or thousands of them - basically every call to CacheManager. Still trying to figure out a reproducible scenario, and what may be happening at the time (isn't cloud development fun?) - in the meantime, any thoughts about it? Could you add some logging and/or defensive programming around that are to help avoid and/or troubleshoot it?