dotnet / orleans

Cloud Native application framework for .NET
https://docs.microsoft.com/dotnet/orleans
MIT License
10.07k stars 2.02k forks source link

Cannot cancel an IAsyncEnumerable #8958

Open pablo-salad opened 5 months ago

pablo-salad commented 5 months ago

An unexpected behavior has been observed while working with IAsyncEnumerable and we try to cancel it. A method returning an IAsyncEnumerable, which internally fetches data from the Channel, encounters no issues to be cancelled when there is data in it. However, if the Channel is empty and the cancellation is requested, there is no execution of code block in the try/finally within the grain.

There is a demo repo to explain this problem in detail.

You'll find three branches detailing various attempts to resolve this issue during our testing phase:

image

image

We would greatly appreciate any assistance on this matter. Thank you!

ReubenBond commented 5 months ago

Thank you for reporting. This is a good point. There needs to be a better way to accomplish this. I'll mark this as a feature enhancement for now. Ideally, we have a better way to flow cancellation along grain call chains in general. GrainCancellationToken is not ideal. Ideally, we would support CancellationToken itself, natively.

koenbeuk commented 5 months ago

Ideally, we would support CancellationToken itself, natively.

This is important to us, do you have a strategy for this in mind and if so, would you elaborate? If possible we'd like to contribute this feature.

ReubenBond commented 5 months ago

This is important to us, do you have a strategy for this in mind and if so, would you elaborate? If possible we'd like to contribute this feature.

The feature needs design work - scenarios/requirements could help to drive the design. Lifetime/scope management for the cancellation is the biggest issue. Eg, do we support cancelling a captured CancellationToken after the sending call has completed? Some rough ideas: