From b3eb4f635031dc8fcb4011f761b9eb9f7a2348f1 Mon Sep 17 00:00:00 2001 From: Smit Patel Date: Tue, 7 Sep 2021 17:42:39 -0700 Subject: [PATCH] Query: Use cancellationToken appropriately --- .../Query/Internal/BufferedDataReader.cs | 26 ++++++++++++++----- ...sitor.ShaperProcessingExpressionVisitor.cs | 10 ++++--- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/EFCore.Relational/Query/Internal/BufferedDataReader.cs b/src/EFCore.Relational/Query/Internal/BufferedDataReader.cs index 745468c6897..4e417c0e94b 100644 --- a/src/EFCore.Relational/Query/Internal/BufferedDataReader.cs +++ b/src/EFCore.Relational/Query/Internal/BufferedDataReader.cs @@ -624,7 +624,11 @@ public override bool NextResult() /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public override Task NextResultAsync(CancellationToken cancellationToken) - => Task.FromResult(NextResult()); + { + cancellationToken.ThrowIfCancellationRequested(); + + return Task.FromResult(NextResult()); + } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -884,16 +888,26 @@ public bool IsDBNull(int ordinal) public bool Read() => IsDataReady = ++_currentRowNumber < _rowCount; -#pragma warning disable IDE0060 // Remove unused parameter public Task GetFieldValueAsync(int ordinal, CancellationToken cancellationToken) - => Task.FromResult(GetFieldValue(ordinal)); + { + cancellationToken.ThrowIfCancellationRequested(); + + return Task.FromResult(GetFieldValue(ordinal)); + } public Task IsDBNullAsync(int ordinal, CancellationToken cancellationToken) - => Task.FromResult(IsDBNull(ordinal)); + { + cancellationToken.ThrowIfCancellationRequested(); + + return Task.FromResult(IsDBNull(ordinal)); + } public Task ReadAsync(CancellationToken cancellationToken) - => Task.FromResult(Read()); -#pragma warning restore IDE0060 // Remove unused parameter + { + cancellationToken.ThrowIfCancellationRequested(); + + return Task.FromResult(Read()); + } public BufferedDataRecord Initialize(DbDataReader reader, IReadOnlyList columns) { diff --git a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs index 314f2e75471..a67cdf1c8f2 100644 --- a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs @@ -1482,10 +1482,11 @@ private static async Task PopulateSplitIncludeCollectionAsync InitializeReaderAsync(tup.Item1, tup.Item2, tup.Item3, cancellationToken), - verifySucceeded: null) + verifySucceeded: null, + queryContext.CancellationToken) .ConfigureAwait(false); - async Task InitializeReaderAsync( + static async Task InitializeReaderAsync( RelationalQueryContext queryContext, RelationalCommandCache relationalCommandCache, bool detailedErrorsEnabled, @@ -1801,10 +1802,11 @@ private static async Task PopulateSplitCollectionAsync InitializeReaderAsync(tup.Item1, tup.Item2, tup.Item3, cancellationToken), - verifySucceeded: null) + verifySucceeded: null, + queryContext.CancellationToken) .ConfigureAwait(false); - async Task InitializeReaderAsync( + static async Task InitializeReaderAsync( RelationalQueryContext queryContext, RelationalCommandCache relationalCommandCache, bool detailedErrorsEnabled,