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

Support for .NET CancellationTokens #9127

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

koenbeuk
Copy link
Contributor

@koenbeuk koenbeuk commented Aug 26, 2024

This PR allows for grain methods to be cancelled using a CancellationToken. The implementation is loosely based on the existing GrainCancellationToken support that is already available.

  1. CodeGen detects the use of a CancellationToken in a grain interface method
  2. If multiple CancellationTokens are used within the same grain interface method then ORLEANS0109 diagnostic is raised
  3. The generated proxy throws early if cancellation is requested. Otherwise it will register for cancellation and sends a one-way message to ICancellableInvokableGrainExtension.CancelRemoteToken to mark this token as canceled
  4. CancellableInvokableGrainExtension looks up the grains ICancellationRuntime component to mark the token as canceled
  5. The generated invokable implements an additional interface: ICancellableInvokable which exposes the method: GetCancellableTokenId
  6. Each instance of a CancellableInvokable sets a cancellableTokenId as Guid.NewGuid()
  7. The InvokeInner implementation on the invokable can optionally interact with an ICancellationRuntime to track cancellation of this invokable.

Once the invokable completes, its CancellationTokenSource obtained through the ICancellationRuntime is always Canceled

Fixes: #8958

Microsoft Reviewers: Open in CodeFlow

@koenbeuk
Copy link
Contributor Author

There is a regression with supporting IAsyncEnumerable with this PR. Will fix that regression and in turn, try and fix #8958

@koenbeuk koenbeuk changed the title Support for .NET CancellationTokens [WIP] Support for .NET CancellationTokens Aug 27, 2024
@koenbeuk koenbeuk changed the title [WIP] Support for .NET CancellationTokens Support for .NET CancellationTokens Aug 27, 2024
@ReubenBond ReubenBond self-assigned this Aug 27, 2024
@koenbeuk koenbeuk changed the title Support for .NET CancellationTokens [WIP] Support for .NET CancellationTokens Aug 28, 2024
@koenbeuk koenbeuk changed the title [WIP] Support for .NET CancellationTokens Support for .NET CancellationTokens Sep 2, 2024
@kzu
Copy link
Contributor

kzu commented Oct 24, 2024

This would be super helpful 🙏

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.

Cannot cancel an IAsyncEnumerable
3 participants