Skip to content

Synchronous factory cancellation escapes timeout classification #7532

Closed

Description

@thomhurst

Summary

The internal timeout helper reports OperationCanceledException when a synchronous task factory observes its expired timeout token before returning a task. It should classify that cancellation as TimeoutException, just as it does when a returned task is canceled. This is a pre-existing edge case; the scheduled test-body path in #7527 does not exercise it.

Reproduction

In tests/TUnit.UnitTests/TimeoutHelperTests.cs, call the ordinary ExecuteWithTimeoutAsync overload with a short timeout and a synchronous factory that waits on token.WaitHandle, calls token.ThrowIfCancellationRequested(), then returns Task.CompletedTask. Assert TimeoutException. Also verify external cancellation keeps OperationCanceledException with the external token.

Expected and actual

Expected: timeout cancellation is classified consistently whether the factory throws synchronously or returns a canceled task. Actual: the factory invocation occurs outside the classification catch, so its synchronous exception escapes.

Source: TimeoutHelper.cs on the checked main commit; review finding.

Acceptance criteria

Route synchronous factory cancellation through the existing token-aware classification, preserving unrelated cancellation and diagnostic exceptions. Add synchronous-throw coverage alongside the returned-canceled-task case. Preserve timer-before-factory ordering and the scheduled-body timeout behavior.

Please make synchronous factory cancellation follow the same classification as returned task cancellation.

Activity

  1. added
    bug
    P3
    on Nov 4, 2026
  2. added
    in-progress
    on Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3bugin-progress

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions