Skip to content

ICompletableSynchronizedStorageSession now inherits from IAsyncDisposable #7329

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

Merged

Conversation

ramonsmits
Copy link
Member

@ramonsmits ramonsmits commented Apr 15, 2025

ICompletableSynchronizedStorageSession now inherits from IAsyncDisposable instead of IDisposable

Alternatively ICompletableSynchronizedStorageSession should not inherit either from IDisposable or IAsyncDisposable as this usually is deferred to the implementation.

However, that causes issue with this specific interfaces as Dispose is used for transaction rollback.

@ramonsmits ramonsmits self-assigned this Apr 15, 2025
@ramonsmits ramonsmits requested a review from awright18 April 15, 2025 11:11
@ramonsmits
Copy link
Member Author

After a discussion with @danielmarbach it became clear that ICompletableSynchronizedStorageSession is not only invoked by LoadHandlersConnector but also via TransactionalSession. TransactionalSession users might the need non-async version thus require both IDisposable and IAsyncDisposable. He suggested to implement both and have a default implementation for IAsyncDisposable to be able to add this as a non breaking change.

…ompletableSynchronizedStorageSession` and revert to also implement `IDisposable` to make this a non-breaking change.
@@ -85,7 +85,7 @@ public MyTask(Context scenarioContext, IServiceProvider provider)
protected override async Task OnStart(IMessageSession session, CancellationToken cancellationToken = default)
{
using (var scope = provider.CreateScope())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should mimic the MainPipelineExecutor's behavior here and use an AsyncScope in these situations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally added this test to verify that usage outside the pipeline works, to make sure transactional session usage will never be broken. I think it would be reasonable to argue we should switch to AsyncScope here, since the core favors that one. Although from a down stream integration perspective, one could argue both scopes should work as long as we support the sync and async variants. Is it reasonable to consider in this test to test both paths?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO that is testing infrastructure. We must assume .net will correctly invoke DisposeAsync and Dispose.

If its important to test Dispose behavior itself wouldn't it be better to have unittests for the specific types?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a fair angle. AsyncScope only then 🪂

@@ -85,7 +85,7 @@ public MyTask(Context scenarioContext, IServiceProvider provider)
protected override async Task OnStart(IMessageSession session, CancellationToken cancellationToken = default)
{
using (var scope = provider.CreateScope())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally added this test to verify that usage outside the pipeline works, to make sure transactional session usage will never be broken. I think it would be reasonable to argue we should switch to AsyncScope here, since the core favors that one. Although from a down stream integration perspective, one could argue both scopes should work as long as we support the sync and async variants. Is it reasonable to consider in this test to test both paths?

@ramonsmits ramonsmits marked this pull request as ready for review April 17, 2025 14:50
@ramonsmits ramonsmits merged commit 0c5d737 into master Apr 17, 2025
4 checks passed
@ramonsmits ramonsmits deleted the ICompletableSynchronizedStorageSession-IAsyncDisposable branch April 17, 2025 14:50
@@ -30,5 +30,7 @@ public void Dispose()
{
}

public ValueTask DisposeAsync() => default;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be removed

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

Successfully merging this pull request may close these issues.

3 participants