From 38675a38d5ff21adf29d18b63e4393d1e52404ce Mon Sep 17 00:00:00 2001 From: Tobias Jamin Date: Wed, 3 Dec 2025 13:10:26 +0100 Subject: [PATCH] Switch SqlDataReader.ReadAsync/SqlDataReader.GetFieldValueAsync to synchronous versions in SqlSessionStateProvicerAsync because there exists a performance issue with reading large data asynchronously (https://github.com/dotnet/SqlClient/issues/593) --- .../SqlSessionStateRepository.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/SqlSessionStateProviderAsync/SqlSessionStateRepository.cs b/src/SqlSessionStateProviderAsync/SqlSessionStateRepository.cs index 1b0cd8f..045a9f2 100644 --- a/src/SqlSessionStateProviderAsync/SqlSessionStateRepository.cs +++ b/src/SqlSessionStateProviderAsync/SqlSessionStateRepository.cs @@ -492,11 +492,13 @@ public async Task GetSessionStateItemAsync(string id, bool exclusiv { using (var reader = await SqlSessionStateRepositoryUtil.SqlExecuteReaderWithRetryAsync(connection, cmd, CanRetryAsync)) { - if (await reader.ReadAsync()) + // use the synchronous versions of Read and GetFieldValue because of performance issues with + // large data described here: https://github.com/dotnet/SqlClient/issues/593 + if (reader.Read()) { // Varbinary(max) should not be returned in an output parameter // Read the returned dataset consisting of SessionItemLong if found - buf = await reader.GetFieldValueAsync(0); + buf = reader.GetFieldValue(0); } }