Skip to content

Commit

Permalink
11685: Restore cancellation token behavior
Browse files Browse the repository at this point in the history
Ensure that cancelling an RPC call does not result in an automatic rejection on the calling side.
Instead the token is passed to the receiving side and handed there. 
This restores the cancellation strategy that was used with the old json-rpc architecture (prior to 1.28)

Contributed on behalf of STMicroelectronics.
Fixes #11685
  • Loading branch information
tortmayr committed Sep 27, 2022
1 parent f11b661 commit 20ec8fb
Showing 1 changed file with 0 additions and 10 deletions.
10 changes: 0 additions & 10 deletions packages/core/src/common/message-rpc/rpc-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,11 @@ export class RpcProtocol {
// The last element of the request args might be a cancellation token. As these tokens are not serializable we have to remove it from the
// args array and the `CANCELLATION_TOKEN_KEY` string instead.
const cancellationToken: CancellationToken | undefined = args.length && CancellationToken.is(args[args.length - 1]) ? args.pop() : undefined;
if (cancellationToken && cancellationToken.isCancellationRequested) {
return Promise.reject(this.cancelError());
}

if (cancellationToken) {
args.push(RpcProtocol.CANCELLATION_TOKEN_KEY);
cancellationToken.onCancellationRequested(() => {
this.sendCancel(id);
this.pendingRequests.get(id)?.reject(this.cancelError());
}
);
}
Expand All @@ -164,12 +160,6 @@ export class RpcProtocol {
output.commit();
}

cancelError(): Error {
const error = new Error('"Request has already been canceled by the sender"');
error.name = 'Cancel';
return error;
}

protected handleCancel(id: number): void {
const cancellationTokenSource = this.cancellationTokenSources.get(id);
if (cancellationTokenSource) {
Expand Down

0 comments on commit 20ec8fb

Please sign in to comment.