Repository navigation
Remove activity cancel tokens once the activity finishes - #1677
Merged
chris-olszewski merged 1 commit intoOct 19, 2026
Merged
chris-olszewski merged 1 commit into
chris-olszewski merged 1 commit into
Conversation
ActivityHalf inserted a CancellationToken into task_tokens_to_cancels for every activity task start and never removed it, so a long-running worker leaked memory per activity attempt. The spawned activity task now removes its entry once the activity future completes, covering success, failure and cancellation. A cancel that arrives afterwards finds no entry and is ignored, as before for unknown tokens. Fixes temporalio#1676 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
chris-olszewski
approved these changes
Oct 19, 2026
This was referenced Nov 3, 2026
chris-olszewski
added a commit
that referenced
this pull request
Nov 3, 2026
* Remove activity cancel tokens once the activity finishes (#1677) ActivityHalf inserted a CancellationToken into task_tokens_to_cancels for every activity task start and never removed it, so a long-running worker leaked memory per activity attempt. The spawned activity task now removes its entry once the activity future completes, covering success, failure and cancellation. A cancel that arrives afterwards finds no entry and is ignored, as before for unknown tokens. Fixes #1676 Co-authored-by: Anshuman Prakash <199287261+Anshuman-Prakash@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 489337e) * Prepare 1.1.2 release --------- Co-authored-by: Anshuman Prakash <nakulsrivastava2004@gmail.com> Co-authored-by: Anshuman Prakash <199287261+Anshuman-Prakash@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes #1676
What changed
ActivityHalf::task_tokens_to_cancelsgot an entry for every activity task start and nothing ever removed it, so worker memory grew with every activity attempt.Arc<parking_lot::Mutex<..>>), and the task removes its own entry as soon as the activity future resolves. Success, failure and cancellation all go through that point. Panics are already caught inside the activity wrapper.Cancelthat arrives after removal finds no entry and is ignored. That matches how unknown tokens were handled before.activity_task_handler, waits for it to finish, checks that the map is empty, then sends a late cancel for the same token.Fixedentry toCHANGELOG.md.Checks run (Docker,
rust:1.94= 1.94.1, protoc 23.4)cargo fmt --all --check: passescargo test -p temporalio-sdk --lib: 40 passed, including the newactivity_cancel_tokens_removed_after_completioncargo clippy -p temporalio-sdk --all-features --tests: no warnings intemporalio-sdk. The one warning in the output is an existingunnecessary_lazy_evaluationsincrates/client/src/lib.rs:720, which this PR doesn't touch.Not run locally: the workspace-wide
cargo lint/cargo test-lintaliases and the integration tests (cargo integ-test).🤖 Generated with Claude Code