From 4faab55dc683021f5254de5458a4e14b1864b26e Mon Sep 17 00:00:00 2001 From: rykalov Date: Sat, 14 Feb 2026 00:14:02 +0500 Subject: [PATCH 1/3] Create TaskCompletionSource with TaskCreationOptions.RunContinuationsAsynchronously in TcsMetricsRequestResultHandler for netstandard --- .../Core/SessionExecuteAsyncTests.cs | 27 +++++++++++++++++++ .../TcsMetricsRequestResultHandler.cs | 4 +++ 2 files changed, 31 insertions(+) diff --git a/src/Cassandra.IntegrationTests/Core/SessionExecuteAsyncTests.cs b/src/Cassandra.IntegrationTests/Core/SessionExecuteAsyncTests.cs index f1867b39b..f05ce28c6 100644 --- a/src/Cassandra.IntegrationTests/Core/SessionExecuteAsyncTests.cs +++ b/src/Cassandra.IntegrationTests/Core/SessionExecuteAsyncTests.cs @@ -14,7 +14,9 @@ // limitations under the License. // using System; +using System.Diagnostics; using System.Linq; +using System.Threading; using System.Threading.Tasks; using NUnit.Framework; @@ -93,5 +95,30 @@ public void SessionExecuteAsyncCQLQueriesParallel() Assert.NotNull(task2.Result.First().GetValue("key")); Assert.NotNull(task3.Result.First().GetValue("tokens")); } + + [Test] + public async Task SessionExecuteAsyncCQLQueriesParallelAndSlowResponseProcessingInUserThread() + { + const int sleepTimeMs = 3_000; + const int maxExpectedWaitingTimeMs = 5_000; + for (var i = 0; i < 3; i++) + { + var sw = Stopwatch.StartNew(); + + var tasks = Enumerable.Range(0, 10) + .Select(_ => Task.Run(async () => + { + var statement = new SimpleStatement("SELECT * FROM system.local"); + await Session.ExecuteAsync(statement).ConfigureAwait(false); + Thread.Sleep(sleepTimeMs); + })) + .ToArray(); + await Task.WhenAll(tasks).ConfigureAwait(false); + + sw.Stop(); + + Assert.Less(sw.ElapsedMilliseconds, maxExpectedWaitingTimeMs); + } + } } } \ No newline at end of file diff --git a/src/Cassandra/Requests/TcsMetricsRequestResultHandler.cs b/src/Cassandra/Requests/TcsMetricsRequestResultHandler.cs index 1e2c008d3..7aa26e4e6 100644 --- a/src/Cassandra/Requests/TcsMetricsRequestResultHandler.cs +++ b/src/Cassandra/Requests/TcsMetricsRequestResultHandler.cs @@ -30,7 +30,11 @@ internal class TcsMetricsRequestResultHandler : IRequestResultHandler public TcsMetricsRequestResultHandler(IRequestObserver requestObserver) { _requestObserver = requestObserver; +#if NET452 _taskCompletionSource = new TaskCompletionSource(); +#else + _taskCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); +#endif } public async Task TrySetResultAsync(RowSet result, SessionRequestInfo sessionRequestInfo) From 6361f6dbf7f79cc8ca034d77e248ffcf20b73e65 Mon Sep 17 00:00:00 2001 From: rykalov Date: Thu, 19 Feb 2026 13:40:29 +0500 Subject: [PATCH 2/3] Configure ThreadPool to pass test SessionExecuteAsyncCQLQueriesParallelAndSlowResponseProcessingInUserThread --- .../Core/SessionExecuteAsyncTests.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Cassandra.IntegrationTests/Core/SessionExecuteAsyncTests.cs b/src/Cassandra.IntegrationTests/Core/SessionExecuteAsyncTests.cs index f05ce28c6..ab0fff211 100644 --- a/src/Cassandra.IntegrationTests/Core/SessionExecuteAsyncTests.cs +++ b/src/Cassandra.IntegrationTests/Core/SessionExecuteAsyncTests.cs @@ -25,6 +25,14 @@ namespace Cassandra.IntegrationTests.Core { public class SessionExecuteAsyncTests : SimulacronTest { + public override void OneTimeSetUp() + { + base.OneTimeSetUp(); + + const int minThreads = 32; + ThreadPool.SetMinThreads(minThreads, minThreads); + } + [Test] public void SessionExecuteAsyncCQLQueryToSync() { From 1b10c8938e553431d0f44fff545b31c90136b2ec Mon Sep 17 00:00:00 2001 From: rykalov Date: Thu, 19 Feb 2026 14:07:22 +0500 Subject: [PATCH 3/3] Add description of PR 622 to changelog --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e11d8c004..877025751 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # ChangeLog - DataStax C# Driver +## 3.23.0 + +TBD + +### New Features + +* [[PR 622](https://github.com/datastax/csharp-driver/pull/622)] Fix some freezes caused by the application running slowly after a request execution + ## 3.22.0 2024-09-30