-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SaveChangesAsync should not wrap OperationCancellationException with DbUpdateException #15074
Comments
Note the same question at the ADO.NET/SqlClient level: https://github.com/dotnet/corefx/issues/9245. I do agree that in general cancellations should be raised as OperationCanceledExceptions rather than domain-specific DbUpdateException/DbException/whatever. |
Notes:
|
Makes sense |
Opened #25631 to track wrapping other exception types for Cosmos |
@AndriySvyryd @ajcvickers we may want to document this as a low-impact breaking change - if anyone's catching DbUpdateException with the expectation that cancellations are included there, that code would no longer work. |
Hi, I am afraid that this issue is still there. This is also seen in this comment which shows how to properly catch the token cancellation: I see it tracked also here: dotnet/SqlClient#26 but there is no resolution of this issue. Are there any plans for this small breaking change or do you suggest any solution, for example using this DbCommandInterceptor? Thank you |
@janseris this issue wasn't meant to fix or work around dotnet/SqlClient#26; it was only about not wrapping OperationCancelledException with DbUpdateException. This helps for other providers which do properly throw OperationCancelledException, but doesn't affect SqlClient which doesn't. However, note that in 7.0 we also did #19526, which is about identifying cancellation exceptions and logging a different message, to allow users to e.g. not log for cancellations. Since there's (apparently) no way to identify cancellation exceptions with SqlClient, the approach there was to look at the cancellation token, and if it's triggered, treat the exception as a cancellation. We could use the same approach and wrap the SqlException in an OperationCancelledException, fixing the SqlClient behavior at the EF level. @janseris can you please open a new issue for us to discuss this? |
Cancellation contract of async methods is broken.
If a method:
SaveChangesAsync(Boolean, CancellationToken)
is called and then cancelled, I would expect to catch an 'OperationCanceledException'. Instead, it throwsDbUpdateException
with the TaskCanceledException as an inner exception.According to the documentation it was designed to be so. But is it a good design decision?
The text was updated successfully, but these errors were encountered: