Skip to content

Fixed Temporalio.Bridge.Scope leaking cancellation tokens#547

Merged
maciejdudko merged 3 commits intotemporalio:mainfrom
maciejdudko:bugfix-540
Oct 27, 2025
Merged

Fixed Temporalio.Bridge.Scope leaking cancellation tokens#547
maciejdudko merged 3 commits intotemporalio:mainfrom
maciejdudko:bugfix-540

Conversation

@maciejdudko
Copy link
Contributor

What was changed

  • Implemented Dispose pattern in Temporalio.Bridge.Scope to correctly release both unmanaged (GCHandle) and managed (CancellationToken) resources.
  • Temporalio.Bridge.CancellationToken now unregisters its callback from the associated System.Threading.CancellationToken when freeing the handle.

Why?

Fixes memory leak due to undisposed core-owned cancellation tokens.

Checklist

  1. Closes [Bug] Memory Leak in Temporalio.Bridge.CancellationToken #540

  2. How was this tested:

Automated testing is not possible for this bug. Manual testing was done following the "Minimal Reproduction" instructions in the linked issue.

@maciejdudko maciejdudko requested a review from a team as a code owner October 23, 2025 20:03
Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

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

Nothing really blocking, but wanted to discuss field nullabillity and such

return;
}

byteArrayRefs.Clear();
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you need to clear these, but not a big deal

@maciejdudko maciejdudko merged commit 35a3efd into temporalio:main Oct 27, 2025
10 checks passed
@maciejdudko maciejdudko deleted the bugfix-540 branch October 27, 2025 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Memory Leak in Temporalio.Bridge.CancellationToken

2 participants