Fix resource leak in AppComponentTest by disposing service scope#105
Fix resource leak in AppComponentTest by disposing service scope#105sfmskywalker merged 3 commits intoenh/102from
Conversation
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses a resource leak in the AppComponentTest base class by adding disposal of the IServiceScope instance that is created but never cleaned up.
- Added
Scope?.Dispose()call in theDispose()method to properly release service scope resources - Used null-conditional operator for safe disposal handling
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public void Dispose() | ||
| { | ||
| OnDispose(); | ||
| Scope?.Dispose(); |
There was a problem hiding this comment.
This change may cause test runner hangs. There's an identical AppComponentTest class in test/modules/servicebus/Elsa.ServiceBus.AzureServiceBus.ComponentTests/Abstractions/AppComponentTest.cs that has a similar Scope property, but the disposal is commented out with an explicit warning: "Disposing the Scope here and in other places where it is created somehow seems to cause the test runner to hang when running other test projects."
Before merging this change, please verify that disposing the Scope in this test class doesn't cause similar hanging issues. Consider running the full test suite, including other test projects, to ensure this doesn't introduce instability.
| Scope?.Dispose(); | |
| // Do not dispose Scope here. Disposing the Scope in similar component test base classes | |
| // has been observed to cause the test runner to hang when running other test projects. |
The
AppComponentTestbase class creates anIServiceScopebut never disposes it, causing resource leaks in the test suite.Changes:
Scope?.Dispose()in theDispose()method to properly clean up service scopes✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.