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

Add ICancellationStrategy extensibility point #541

Merged
merged 2 commits into from
Sep 4, 2020

Conversation

AArnott
Copy link
Member

@AArnott AArnott commented Sep 3, 2020

This allows specific JsonRpc instances to be configured to implement CancellationToken support in a totally different way. They are not given the freedom to mutate the the request object itself, but they may trigger and respond to any other JSON-RPC message or do something entirely out of band (e.g. creating a file and/or testing for existing of the file).

As part of this change, we had to move $/cancelRequest handling out of its very special place in JsonRpc.HandleRpcAsync into a standard method handler. But that would have changed the method handler to be invoked on the user-configurable SynchronizationContext (which is now by default order-preserving). But this special method shouldn't be subject to that order-preserving SynchronizationContext because in fact we want these cancellation requests handled as soon as they come in so they can cancel an ongoing RPC server method that has not yet yielded. In order to support this, I modified how we record TargetMethod to include an optional override SynchronizationContext.

Closes #436

@AArnott AArnott added this to the v2.6 milestone Sep 3, 2020
@AArnott AArnott self-assigned this Sep 3, 2020
@codecov-commenter
Copy link

codecov-commenter commented Sep 3, 2020

Codecov Report

Merging #541 into master will increase coverage by 0.13%.
The diff coverage is 95.60%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #541      +/-   ##
==========================================
+ Coverage   89.72%   89.86%   +0.13%     
==========================================
  Files          53       54       +1     
  Lines        4420     4438      +18     
==========================================
+ Hits         3966     3988      +22     
+ Misses        454      450       -4     
Impacted Files Coverage Δ
src/StreamJsonRpc/StandardCancellationStrategy.cs 92.30% <92.30%> (ø)
src/StreamJsonRpc/JsonRpc.cs 92.69% <100.00%> (+0.21%) ⬆️
...reamJsonRpc/Reflection/MethodSignatureAndTarget.cs 76.92% <100.00%> (+4.19%) ⬆️
src/StreamJsonRpc/Reflection/TargetMethod.cs 95.18% <100.00%> (+0.30%) ⬆️
src/StreamJsonRpc/Protocol/JsonRpcRequest.cs 85.10% <0.00%> (-2.13%) ⬇️
src/StreamJsonRpc/MessagePackFormatter.cs 92.00% <0.00%> (+0.28%) ⬆️
...treamJsonRpc/Exceptions/ConnectionLostException.cs 75.00% <0.00%> (+25.00%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fde90ef...d535fbf. Read the comment docs.

This allows specific JsonRpc instances to be configured to implement `CancellationToken` support in a totally different way. They are *not* given the freedom to mutate the the request object itself, but they may trigger and respond to any other JSON-RPC message or do something entirely out of band (e.g. creating a file and/or testing for existing of the file).

As part of this change, we had to move `$/cancelRequest` handling out of its very special place in `JsonRpc.HandleRpcAsync` into a standard method handler. But that would have changed the method handler to be invoked on the user-configurable `SynchronizationContext` (which is now by default order-preserving). But this special method *shouldn't* be subject to that order-preserving `SynchronizationContext` because in fact we want these cancellation requests handled as soon as they come in so they can cancel an ongoing RPC server method that has not yet yielded. In order to support this, I modified how we record `TargetMethod` to include an optional override `SynchronizationContext`.
Copy link

@heejaechang heejaechang left a comment

Choose a reason for hiding this comment

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

thank you!

src/StreamJsonRpc/StandardCancellationStrategy.cs Outdated Show resolved Hide resolved
This is important to support strategy implementations that create a file in `CancelOutboundRequest` and must delete it when the cancellation request has completed.
@AArnott AArnott merged commit c22aca8 into microsoft:master Sep 4, 2020
@AArnott AArnott deleted the fix436 branch September 4, 2020 14:47
@heejaechang
Copy link

@AArnott thank you! when will this be inserted to VS?

@heejaechang
Copy link

@huguesv for FYI

@AArnott
Copy link
Member Author

AArnott commented Sep 4, 2020

@heejaechang StreamJsonRpc insertions happen nightly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support new CancellationStrategy capability added to vscode-jsonrpc in StreamjsonRpc
4 participants