Repository navigation
Keep cancellation token source cancellation idempotent - #1952
Merged
Dirk Bäumer (dbaeumer) merged 2 commits intoNov 24, 2026
Merged
Dirk Bäumer (dbaeumer) merged 2 commits into
Dirk Bäumer (dbaeumer) merged 2 commits into
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the JSON-RPC cancellation idempotency change.
No open issues 🎉
What changed in this PR
Makes JSON-RPC cancellation idempotent by avoiding calls to cancel() on immutable token sentinels, while preserving existing behavior for materialized tokens.
Changes:
- Restricts cancellation calls to
MutableTokeninstances. - Adds four lifecycle tests covering repeated cancellation, disposal, and listener notifications.
- Includes the shared cancellation tests in the browser test bundle.
| File | Description |
|---|---|
jsonrpc/src/common/test/cancellation.test.ts |
Adds four cancellation lifecycle regression tests. |
jsonrpc/src/common/cancellation.ts |
Guards cancellation with a MutableToken instance check. |
jsonrpc/src/browser/test/webpack.config.js |
Adds the compiled cancellation tests to the browser bundle. |
Review effort: Balanced
Dirk Bäumer (dbaeumer)
previously approved these changes
Nov 24, 2026
Member
|
Copilot resolve the merge conflicts in this pull request |
1 similar comment
Member
|
Copilot resolve the merge conflicts in this pull request |
Dirk Bäumer (dbaeumer)
approved these changes
Nov 24, 2026
Federico Brancasi (federicobrancasi)
approved these changes
Nov 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Avoid calling
cancel()on the immutableCancellationToken.CancelledandCancellationToken.Nonesentinels.CancellationTokenSourceuses those objects when cancelled or disposed before its token is accessed. A latercancel()currently casts the sentinel toMutableTokenand throwsTypeError: this._token.cancel is not a function:Only invoke
cancel()when the stored token is actually aMutableToken, matching the existing type check indispose(). Preserve the lazy immutable sentinels and the current behavior of materialized tokens.Tests
Add four shared lifecycle tests and include their compiled module in the browser test bundle:
CancellationToken.Cancelled;CancellationToken.None;Before the source change, the first two tests reproduce the TypeError and the two listener controls pass. All four now pass in Node.js and Chromium.
Validation
Based on current upstream main (
898f44d0):npm run compile:jsonrpcnpm --prefix jsonrpc run test:node -- --reporter dot(83 passing)npm --prefix jsonrpc run lint(passed; existing Stylistic configuration deprecation notice)npm --prefix jsonrpc run test:browser(17 passing in headless Chromium)git diff --checkNo public API, wire-format, package-version, or dependency changes. Other package suites and VS Code integration tests were not run. AI assistance was used to develop and validate this change.