Skip to content

Dispose CancellationTokenSource in DistributedTracingSample#650

Closed
Copilot wants to merge 1 commit intotorosent/add-otel-samplefrom
copilot/sub-pr-637
Closed

Dispose CancellationTokenSource in DistributedTracingSample#650
Copilot wants to merge 1 commit intotorosent/add-otel-samplefrom
copilot/sub-pr-637

Conversation

Copy link
Contributor

Copilot AI commented Feb 27, 2026

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