Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
35 changes: 35 additions & 0 deletions src/Cassandra.IntegrationTests/Core/SessionExecuteAsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
{
Expand Down Expand Up @@ -93,5 +103,30 @@ public void SessionExecuteAsyncCQLQueriesParallel()
Assert.NotNull(task2.Result.First().GetValue<string>("key"));
Assert.NotNull(task3.Result.First().GetValue<string[]>("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);
}
}
}
}
4 changes: 4 additions & 0 deletions src/Cassandra/Requests/TcsMetricsRequestResultHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ internal class TcsMetricsRequestResultHandler : IRequestResultHandler
public TcsMetricsRequestResultHandler(IRequestObserver requestObserver)
{
_requestObserver = requestObserver;
#if NET452
_taskCompletionSource = new TaskCompletionSource<RowSet>();
#else
_taskCompletionSource = new TaskCompletionSource<RowSet>(TaskCreationOptions.RunContinuationsAsynchronously);
#endif
}

public async Task TrySetResultAsync(RowSet result, SessionRequestInfo sessionRequestInfo)
Expand Down