Azure / Azure/azure-functions-host

CancellationTokenSource leak in PendingItem timeout constructor

Open
#11,653 3 comments 0 reactions 2 assignees Claimed by @satvu View on GitHub
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 12h
Merged PRs (30d)
38

Description

The `PendingItem` class in `WorkerChannelBase.cs` (previously `GrpcWorkerChannel.cs`) creates a `CancellationTokenSource` via `CancelAfter` in the timeout constructor, but never disposes it. Only the `CancellationTokenRegistration` is disposed — the underlying CTS and its timer remain alive.

Under repeated registrations (e.g., frequent gRPC message callbacks with timeouts), this can leak timers and resources.

### Location

`src/WebJobs.Script.Grpc/Channel/WorkerChannelBase.cs` — `PendingItem` nested class, timeout constructor.

### Fix

Store the `CancellationTokenSource` as a field and dispose it in both the success (`SetResult`) and timeout (`OnTimeout`) paths.

### Context

Found during PR review: https://github.com/Azure/azure-functions-host/pull/11652#discussion_r2933116426

This is a pre-existing issue — the code was moved verbatim from `GrpcWorkerChannel` during the M1 refactor.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.