Skip to content

CancellationTokenExtensions.CombineWith() forgets the original token when combining 3 or more tokens #1442

Closed

Description

Bug description

This method can be used to combine an arbitrary number of cancellation tokens:

public static CombinedCancellationToken CombineWith(this CancellationToken original, params CancellationToken[] others)

If more than 2 of the provided tokens (including the original one that the extension method was called on) can be cancelled, the method goes into the least optimized code path here:

This code path forgets about the "original" cancellation token, and only combines the "others". As a result, the resulting combined cancellation token does not react to cancellation of the "original" token.

Repro steps

Described above.

Expected behavior

The resulting combined cancellation token should include and reflect cancellations on the "original" token as well as any "others".

Actual behavior

Instead the resulting combined cancellation token ignores the "original" token and only reflects cancellation on the "others".

  • Version used: 17.11.20

Activity

  1. AArnott commented on Mar 25, 2025

    @AArnott
    Member

    Good catch. Thanks for reporting.
    I'll get this fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions