Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service Fabric support for IDisposable Stateful/Stateless Services #354

Open
besseb05 opened this issue Oct 3, 2023 · 0 comments
Open

Comments

@besseb05
Copy link

besseb05 commented Oct 3, 2023

Problem
We are working with Service Fabric services in production, and our services create native resources which implement IDisposable. In order to dispose of these resources correctly, we made our services also implement IDisposable, but Service Fabric currently doesn't support disposing of the service objects, which has led to a buildup of resources. We have added logic for disposing of the resources in OnCloseAsync() and OnAbort(), but this has still caused issues.

In particular, we noticed this problem when due to some issues, our service failed to start up and repeatedly threw exceptions in the OnOpenAsync() method. When this happens, the Service Fabric runtime never calls OnCloseAsync() on the service object, and doesn't dispose it either before creating a new instance. After a short while, since the resources we were allocating never got disposed, it caused the memory and thread count of our service to increase substantially.

Proposed solution
At the end of the lifetime of the service object, if the service implements theIDisposable interface, call the Dispose() method on it. This will help ensure services which allocate native resources will be able to reliably clean them up.

Alternatives considered
As mentioned above, we have tried to ensure that these resources are always cleaned up by disposing of them in the OnCloseAsync() and OnAbort().

@besseb05 besseb05 changed the title Service Fabric support for IDisposable Stateful/Stateless settings Service Fabric support for IDisposable Stateful/Stateless Services Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant