Skip to content

Inconsistent Cancellation Behavior in StrawberryShake client #9023

@ben-hamida

Description

@ben-hamida

Product

Strawberry Shake

Version

15.1.11

Link to minimal reproduction

https://github.com/ben-hamida/StrawberryShake-Cancellation-Repro

Steps to reproduce

Run the tests in my repro. The first test shows how a request that is canceled early throws an IncalidOperationException. The seconds test shows when canceled late, an error result is returned instead.

What is expected?

Both cases should throw an InvalidOperationException.

What is actually happening?

When cancellation is signaled early an OperationCanceledException is thrown, while if it is signaled late an error is reported in the returned result type instead with the message "A task was canceled."

Relevant log output

Additional context

In StrawberryShake.Transport.Http.ResponseEnumerable, any OperationCanceledException that client.SendAsync might throw will propagated up, while if it's thrown by result.ReadAsResultStreamAsync or enumerator.MoveNextAsync it is caught and converted into a JsonDocument.

The most idiomatic behavior is to let it bubble up. When converted into a generic result type it becomes difficult to distinguish it from other errors. For example in an ASP Core application it's often desirable to let OperationCanceledException be handled by the framework without logging it as an error, while other errors we often want to catch early and log.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions