Skip to content

Dispose CancellationTokenSource in DistributedTracingSample - #650

Closed
Tomer Rosenthal (torosent) with Copilot wants to merge 1 commit into
torosent/add-otel-samplefrom
copilot/sub-pr-637
Closed

Tomer Rosenthal (torosent) with Copilot wants to merge 1 commit into
torosent/add-otel-samplefrom
copilot/sub-pr-637

Conversation

Copilot AI commented Feb 27, 2026 •

Copy link
Copy Markdown
Contributor

CancellationTokenSource created with a TimeSpan constructor internally allocates a timer that must be explicitly disposed. The inline construction in Program.cs skipped disposal.

Change

Assign the CancellationTokenSource to a using-declared local variable so the timer is released when it goes out of scope:

// Before
OrchestrationMetadata result = await client.WaitForInstanceCompletionAsync(
    instanceId,
    getInputsAndOutputs: true,
    new CancellationTokenSource(TimeSpan.FromSeconds(60)).Token);

// After
using CancellationTokenSource timeoutCts = new CancellationTokenSource(TimeSpan.FromSeconds(60));
OrchestrationMetadata result = await client.WaitForInstanceCompletionAsync(
    instanceId,
    getInputsAndOutputs: true,
    timeoutCts.Token);

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI mentioned this pull request Feb 27, 2026
9 of 15 tasks
Copilot AI changed the title [WIP] Update OpenTelemetry sample and dependency adjustments Dispose CancellationTokenSource in DistributedTracingSample Feb 27, 2026
@torosent
Tomer Rosenthal (torosent) marked this pull request as ready for review February 27, 2026 20:03
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.

2 participants