dotnet / dotnet/efcore

Inconsistent behaviour for cancellation token for EnableRetryOnFailure

Open
#37,061 4 comments 1 reaction 1 assignee Claimed by @AndriySvyryd View on GitHub
customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

### Bug description

Calling sql and then cancelling without `EnableRetryOnFailure` => `InvalidOperationException` ("An exception has been raised that is likely due to a transient failure. Consider enabling transient error resiliency by adding 'EnableRetryOnFailure' to the 'UseSqlServer' call")

Calling sql and then cancelling with `EnableRetryOnFailure` => `OperationCanceledException` (correct)

### Your code

```csharp
`SqlServerExecutionStrategy` does not check for cancellation token on error

`SqlServerRetryingExecutionStrategy` does not check for cancellation token on error either and therefore logs the "transient" "error". The following retry checks calls `cancellationToken.ThrowIfCancellationRequested()` and thus the correct exception is thrown.
```

### Stack traces

```text

```

### Verbose output

```text

```

### EF Core version

9.0.10

### Database provider

SqlServer

### Target framework

_No response_

### Operating system

_No response_

### IDE

_No response_

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.