-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Conversation
There is a regression with supporting |
This would be super helpful 🙏 |
@koenbeuk is there anything remaining here or is this ready for review? Apologies for the delay |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 6 out of 21 changed files in this pull request and generated 2 comments.
Files not reviewed (15)
- src/Orleans.Runtime/Cancellation/CancellableInvokableGrainExtension.cs: Evaluated as low risk
- src/Orleans.Serialization/Invocation/ICancellationRuntime.cs: Evaluated as low risk
- src/Orleans.Runtime/Hosting/DefaultSiloServices.cs: Evaluated as low risk
- src/Orleans.Runtime/Core/InsideRuntimeClient.cs: Evaluated as low risk
- src/Orleans.Runtime/Cancellation/CancellationRuntime.cs: Evaluated as low risk
- test/Grains/TestGrainInterfaces/IGenericInterfaces.cs: Evaluated as low risk
- src/Orleans.Core/Runtime/SharedCallbackData.cs: Evaluated as low risk
- test/Orleans.Serialization.UnitTests/BuiltInCodecTests.cs: Evaluated as low risk
- src/Orleans.CodeGenerator/LibraryTypes.cs: Evaluated as low risk
- src/Orleans.Core/Runtime/OutsideRuntimeClient.cs: Evaluated as low risk
- src/Orleans.CodeGenerator/SerializerGenerator.cs: Evaluated as low risk
- src/Orleans.CodeGenerator/Model/InvokableMethodDescription.cs: Evaluated as low risk
- src/Orleans.CodeGenerator/AnalyzerReleases.Unshipped.md: Evaluated as low risk
- src/Orleans.CodeGenerator/InvokableGenerator.cs: Evaluated as low risk
- test/Grains/TestGrains/GenericGrains.cs: Evaluated as low risk
Comments suppressed due to low confidence (2)
src/Orleans.Serialization/Invocation/ICancellableInvokable.cs:21
- [nitpick] The method name 'GetCancellableTokenId' is ambiguous. It should be renamed to 'GetCancellationTokenId' for better clarity.
Guid GetCancellableTokenId();
src/Orleans.Core/Runtime/CallbackData.cs:34
- The SubscribeForCancellation method introduces new behavior that should be covered by tests to ensure it works correctly under various scenarios (e.g., token already canceled, token gets canceled after registration).
public void SubscribeForCancellation(IInvokable invokable)
fe48efd
to
b86f46e
Compare
(rebased on main) |
This reverts commit d2334d7.
b86f46e
to
2c5355a
Compare
@koenbeuk thank you for great work on this PR and for your patience. I have pushed some updates to implement the identification strategy we discussed (using sender's I added two config options on /// <summary>
/// Whether request cancellation should be attempted when a request times out.
/// </summary>
/// <remarks>
/// Request cancellation may involve sending a cancellation message to the silo which hosts the target grain.
/// Defaults to <see langword="true"/>.
/// </remarks>
public bool CancelRequestOnTimeout { get; set; } = true;
/// <summary>
/// Whether local calls should be cancelled immediately when cancellation is signaled (<see langword="false"/>)
/// rather than waiting for callees to acknowledge cancellation before a call is considered cancelled (<see langword="true"/>).
/// </summary>
/// <remarks>
/// Defaults to <see langword="false"/>.
/// </remarks>
public bool WaitForCancellationAcknowledgement { get; set; }
I'm not sure that we necessarily need to make these things configurable, but I erred on this side. I changed the codegen to include a I updated the I implemented batching for cancellation to hopefully reduce the impact of large volumes of cancellations on the wire - one might expect cancellation rates to increase when load increases. If that also leads to a significant increase in network traffic / CPU load, that could make the situation worse, so I felt that some batching was warranted.
|
90a78cb
to
f346034
Compare
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.
CancellationToken
in a grain interface methodICancellableInvokableGrainExtension.CancelRemoteToken
to mark this token as canceledCancellableInvokableGrainExtension
looks up the grainsICancellationRuntime
component to mark the token as canceledICancellableInvokable
which exposes the method:GetCancellableTokenId
CancellableInvokable
sets a cancellableTokenId asGuid.NewGuid()
InvokeInner
implementation on the invokable can optionally interact with anICancellationRuntime
to track cancellation of this invokable.Once the invokable completes, its CancellationTokenSource obtained through the
ICancellationRuntime
is always CanceledFixes: #8958
Microsoft Reviewers: Open in CodeFlow