`Connection already has associated data reader` guard missing
I've been testing handling of multiple open queries per single connection functionality for provider and discovered that provider hangs instead of one of two options:
- executing second query (I suspect ClickHouse TCP protocol doesn't support it)
- throwing guard exception if it is not supported by protocol/provider
Repro:
using var cn = new ClickHouseConnection(cs);
cn.Open();
using var cmd1 = cn.CreateCommand();
cmd1.CommandText = "select * from system.tables";
using var rd1 = cmd1.ExecuteReader();
using var cmd2 = cn.CreateCommand();
cmd2.CommandText = "select * from system.tables";
// hangs here in ClickHouseTcpClient.OpenSession() call
using var rd2 = cmd2.ExecuteReader();
System.Private.CoreLib.dll!System.Threading.Monitor.Wait(object obj, int millisecondsTimeout)
System.Private.CoreLib.dll!System.Threading.SemaphoreSlim.WaitUntilCountOrTimeout(int millisecondsTimeout, uint startTime, System.Threading.CancellationToken cancellationToken)
System.Private.CoreLib.dll!System.Threading.SemaphoreSlim.Wait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken)
Octonica.ClickHouseClient.dll!Octonica.ClickHouseClient.ClickHouseTcpClient.OpenSession(bool async, Octonica.ClickHouseClient.IClickHouseSessionExternalResources externalResources, System.Threading.CancellationToken sessionCancellationToken, System.Threading.CancellationToken cancellationToken)
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start<Octonica.ClickHouseClient.ClickHouseTcpClient.<OpenSession>d__15>(ref Octonica.ClickHouseClient.ClickHouseTcpClient.<OpenSession>d__15 stateMachine)
Octonica.ClickHouseClient.dll!Octonica.ClickHouseClient.ClickHouseCommand.OpenSession(bool closeConnection, bool async, System.Threading.CancellationToken cancellationToken)
Octonica.ClickHouseClient.dll!Octonica.ClickHouseClient.ClickHouseCommand.ExecuteDbDataReader(System.Data.CommandBehavior behavior, bool ignoreProfileEvents, bool async, System.Threading.CancellationToken cancellationToken)
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start<Octonica.ClickHouseClient.ClickHouseCommand.<ExecuteDbDataReader>d__83>(ref Octonica.ClickHouseClient.ClickHouseCommand.<ExecuteDbDataReader>d__83 stateMachine)
Octonica.ClickHouseClient.dll!Octonica.ClickHouseClient.ClickHouseCommand.ExecuteReader()
Thank you for the report, we are on vacation)
Will fix this and other issues on next week.
Hm, looks like it is or beloved MARS feature from MS SQL server. I doubt CH supports this, even in npgsql it is still "in progress" https://github.com/npgsql/npgsql/issues/462 @victor-sushko can we throw exception something like "OperationInProgressException: A command is already in progress"
Exception is fine as far as it doesn't hang like it does now.
BTW, npgsql (and also mysql) are actually exceptions here - most of databases we test support multiple queries over one connection.