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 diff --git a/src/Cassandra.IntegrationTests/Core/SessionExecuteAsyncTests.cs b/src/Cassandra.IntegrationTests/Core/SessionExecuteAsyncTests.cs index f1867b39b..ab0fff211 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; @@ -23,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() { @@ -93,5 +103,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)