Skip to content
This repository was archived by the owner on Aug 1, 2024. It is now read-only.
This repository was archived by the owner on Aug 1, 2024. It is now read-only.

In .NET Core, cancelling a CancellationToken can result in either a StorageException or a TaskCanceledException #512

Open
@brettsam

Description

@brettsam

In .NET Core (v8.2.1), canceling a storage operation sometimes results in a StorageException with an inner TaskCanceledException. Other times, the top-level exception is TaskCanceled.

I ran this test in both the desktop framework and core:

private static async Task GetAndCancel(CloudQueue queue)
{
    count++;
    var cts = new CancellationTokenSource();
    var task = queue.GetMessagesAsync(100, null, null, null, cts.Token);
    cts.Cancel();
    try
    {
        await task;
    }
    catch (StorageException ex)
    {
        Console.WriteLine($"Storage  {count}");
    }
    catch (OperationCanceledException ex)
    {
        Console.WriteLine($"Canceled {count}");
    }
}

Full Fx (both 7.2.1 and 8.2.1), the output is:

Canceled 1
Canceled 2
Canceled 3
Canceled 4
Canceled 5
Canceled 6
Canceled 7
Canceled 8
Canceled 9
Canceled 10

With Core, the output is:

Canceled 1
Storage  2
Storage  3
Canceled 4
Canceled 5
Storage  6
Storage  7
Canceled 8
Canceled 9
Storage  10

We have code throughout our project to handle the TaskCanceledException, but now we need to add extra handling for StorageException with an inner exception.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions