Skip to content

Cannot cancel an IAsyncEnumerable #8958

@pablo-salad

Description

@pablo-salad

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:

  • main: The channel has data and the cancellation works as expected.

image

  • empty_iasyncenumerable: The channel is empty and the cancellation is called but it didn't cancel the grain code.

image

  • graincancellationtoken: We tried to pass a GrainCancellationToken to the GetCount method and initiate its cancellation upon request from another CancellationToken but unfortunately, the cancellation process did not succeed. Same behavior as in empty_iasyncenumerable.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions