Repository navigation
Report command failures while reading results - #39405
Conversation
- Notify command interceptors about provider reader failures. - Cover query reads, cancellation, and SaveChanges result advancement. Fixes dotnet#35229
- Include failure and cancellation logging consumers when enabling reader reporting. - Cover buffered reads, result advancement, materialization boundaries, and SQLite overflow.
|
@dotnet-policy-service agree |
There was a problem hiding this comment.
🔵 Needs a closer look
Human validation is warranted because the cross-cutting diagnostics changes affect async reader lifetimes, callback reentrancy, provider-specific behavior, and extensibility cases not covered by the focused tests.
No open issues 🎉
What changed in this PR
This pull request reports provider failures from DbDataReader.Read and NextResult through existing command failure or cancellation callbacks across query enumeration, buffering, and batched SaveChanges.
Changes:
- Added centralized synchronous and asynchronous reader-error reporting.
- Routed streaming, buffered, grouped-query, and modification-batch reader advancement through reporting-aware paths.
- Added regression coverage for failures, cancellation, diagnostics, interceptors, disposal, and materialization behavior.
| File | Summary |
|---|---|
test/EFCore.Sqlite.FunctionalTests/CommandInterceptionSqliteTest.cs |
Adds SQLite overflow and batched SaveChanges regression coverage. |
test/EFCore.Relational.Tests/Storage/RelationalCommandTest.cs |
Covers reader failures, cancellation, buffering, diagnostics, logging, interception, and disposal. |
test/EFCore.Relational.Specification.Tests/CommandInterceptionTestBase.cs |
Adds shared query read-failure, cancellation, and materialization tests. |
src/EFCore.Relational/Update/AffectedCountModificationCommandBatch.cs |
Routes batched result advancement through reporting-aware methods. The new synchronous and asynchronous paths bypass the existing virtual DbDataReader extension point, potentially skipping provider-decorated readers. |
src/EFCore.Relational/Storage/RelationalDataReader.cs |
Adds synchronous and asynchronous reader-advancement reporting. The asynchronous helper can dereference cleared reporting state after disposal while an operation is pending, potentially masking the provider exception with a NullReferenceException. |
src/EFCore.Relational/Storage/RelationalCommand.cs |
Creates and configures command-error reporting for reader execution. |
src/EFCore.Relational/Storage/Internal/RelationalCommandErrorReporter.cs |
Centralizes command failure and cancellation callback dispatch. |
src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.ClientMethods.cs |
Routes split-query reader advancement through reporting-aware methods. |
src/EFCore.Relational/Query/Internal/GroupBySplitQueryingEnumerable.cs |
Uses reporting-aware reader advancement for grouped split queries. |
src/EFCore.Relational/Query/Internal/GroupBySingleQueryingEnumerable.cs |
Uses reporting-aware reader advancement for grouped single queries. |
src/EFCore.Relational/Query/Internal/BufferedDataReader.cs |
Reports provider failures encountered while buffering rows and advancing result sets. |
src/EFCore.Relational/Diagnostics/IDbCommandInterceptor.cs |
Documents callbacks for reader-consumption failures and cancellation. |
Review effort: Lite
|
Some tests in NonSharedModelUpdatesSqlServerTest and IncompleteMappingInheritanceQuerySqlServerTest suites are failing. You need to exclude the errors from the SQL logger used in tests. |
|
Update for @AndriySvyryd: fixed in commit d3abe0d. TestSqlLoggerFactory excludes CommandError events from SQL baselines and parameter history while retaining failed SQL in FailedSqlStatements for diagnostics. Locally, the full affected suites pass: NonSharedModelUpdatesSqlServerTest 23/23, IncompleteMappingInheritanceQuerySqlServerTest 98 passed and 4 skipped, and DataAnnotationSqlServerTest 102/102. The Build and Agent Harness Coverage workflows currently show action_required, so GitHub CI has not reported test results. |
|
@Shivansh-Gaur2 Looks like the SQL logger now captures less than expected. Tests in PrimitiveCollectionsQuerySqliteTest, TPTGearsOfWarQuerySqliteTest and JsonQueryJsonTypeSqlServerTest are failing |
|
@AndriySvyryd, thanks for catching that. I fixed it in a63428a. Failed SQL stays in the logger history; the baseline comparison now skips only unexpected errors. I ran the SQLite functional suite and the affected SQL Server tests locally, and they passed. I couldn't run the SQL Server 2025-only migration test on my SQL Server 2019 instance. The CI test workflows are still waiting for approval. |
AndriySvyryd
left a comment
There was a problem hiding this comment.
Thanks for your contribution!
Fixes #35229
A provider can raise a database error from
DbDataReader.ReadorNextResultafterExecuteReadersucceeds. These errors currently bypassCommandFailed, affecting both query enumeration and batchedSaveChanges.This change reports provider reader-advancement failures through the existing command failure callbacks, including sync, async, and buffered consumption. Cancellations use
CommandCanceled. EF row materialization exceptions remain on the query-iteration path, andQueryIterationFailedis preserved.Reporting accounts for ordinary
ILoggerlogging, event-specific diagnostic listeners, and command interceptors independently. No supported public API is added.Validation
abs(long.MinValue)reproduction in sync/async and streaming/buffered modes.git diff --check: passed.Checklist
.github/CONTRIBUTING.md.