DataAction / AdoNetCore.AseClient

AdoNetCore.AseClient - a .NET Core DB Provider for SAP ASE
Apache License 2.0
106 stars 44 forks source link

[linq2db] ArgumentException : Cannot change internal connection state as it is Broken #50

Closed MaceWindu closed 6 years ago

MaceWindu commented 6 years ago

This error generated by next test after failure from #48, so I think it should be fixed prior to #48 while it should be easy to reproduce. Second test do following query:

Assert.That(conn.Execute<string>     ("SELECT '<xml/>'"),            Is.EqualTo("<xml/>"));
Result StackTrace:  
at AdoNetCore.AseClient.Internal.ConnectionPool.Reserve()
   at AdoNetCore.AseClient.Internal.ConnectionPoolManager.Reserve(String connectionString, IConnectionParameters parameters)
   at AdoNetCore.AseClient.AseConnection.Open()
   at LinqToDB.Data.DataConnection.get_Connection() in c:\GitHub\linq2db.work\Source\LinqToDB\Data\DataConnection.cs:line 883
   at LinqToDB.Data.DataConnection.CreateCommand() in c:\GitHub\linq2db.work\Source\LinqToDB\Data\DataConnection.cs:line 979
   at LinqToDB.Data.DataConnection.get_Command() in c:\GitHub\linq2db.work\Source\LinqToDB\Data\DataConnection.cs:line 970
   at LinqToDB.DataProvider.DataProviderBase.InitCommand(DataConnection dataConnection, CommandType commandType, String commandText, DataParameter[] parameters) in c:\GitHub\linq2db.work\Source\LinqToDB\DataProvider\DataProviderBase.cs:line 104
   at LinqToDB.Data.DataConnection.InitCommand(CommandType commandType, String sql, DataParameter[] parameters, List`1 queryHints) in c:\GitHub\linq2db.work\Source\LinqToDB\Data\DataConnection.cs:line 950
   at LinqToDB.Data.CommandInfo.Execute[T]() in c:\GitHub\linq2db.work\Source\LinqToDB\Data\CommandInfo.cs:line 549
   at LinqToDB.Data.DataConnectionExtensions.Execute[T](DataConnection connection, String sql) in c:\GitHub\linq2db.work\Source\LinqToDB\Data\DataConnectionExtensions.cs:line 1069
   at Tests.DataProvider.SybaseTests.TestXml(String context) in c:\GitHub\linq2db.work\Tests\Linq\DataProvider\SybaseTests.cs:line 422
--ArgumentException
   at AdoNetCore.AseClient.Internal.InternalConnection.SetState(InternalConnectionState newState)
   at AdoNetCore.AseClient.Internal.InternalConnection.set_IsDoomed(Boolean value)
   at AdoNetCore.AseClient.Internal.InternalConnection.Ping()
   at AdoNetCore.AseClient.Internal.ConnectionPool.FetchIdlePooledConnection()
   at AdoNetCore.AseClient.Internal.ConnectionPool.<ReservePooledConnection>d__13.MoveNext()
Result Message: 
AdoNetCore.AseClient.AseException : No message provided
  ----> System.ArgumentException : Cannot change internal connection state as it is Broken

linq2db test: SybaseTests.TestTimeSpan + SybaseTests.TestXml

MaceWindu commented 6 years ago

I think failure in #48 doesn't shutdown connection properly. In debugger I see that second test creates new connection and receive old connection from pool with state Closed. For such connections we call Open and then it fails

senseibaka commented 6 years ago

Yeah, in this case the InvalidCastException causes the driver to not properly return the connection to the pool, so the next use of the pooled connection detects that it wasn't returned properly and reports it as broken (rather than try to use it).

However, internally we should be trying to RemoveAndReplace(connection), so something went wrong here too.

Fix will be:

MaceWindu commented 6 years ago

Can confirm that fix works