We have an application using the IBM Informix driver. Whenever we try to open connections in parallel, we start getting some really weird errors.
This is the smallest reproduction code I could come up with:
const int Count = 10;
const string ConnectionString = "Host=the_host;Service=the_service;Server=the_server;Database=the_database;User ID=the_user_id;Password=the_password";
static void Main()
{
var threads = new Thread[Count];
for (var i = 0; i < threads.Length; i++)
{
threads[i] = new Thread(
number =>
{
using (var conn = new IfxConnection(ConnectionString))
{
Console.WriteLine("Opening connection {0}... ", number);
try
{
conn.Open();
Console.WriteLine("Opened connection {0}", number);
var setLockCommand = conn.CreateCommand();
setLockCommand.CommandText = "set lock mode to wait 10;";
setLockCommand.ExecuteNonQuery();
Console.WriteLine("Releasing connection {0}", number);
}
catch (IfxException ex)
{
Console.WriteLine("Failed opening connection {0}: {1}", number, ex);
}
}
});
threads[i].Start(i);
}
foreach (var thread in threads)
thread.Join();
}
Depending on which machine we run it on, we had to play a little with the Count
value to make it fail, but 10 seems to reproduce the error consistently.
Of course this is not production code, nor how we handle threading, but it highlights the issue without introducting any other variables.
This is the exception stack trace:
IBM.Data.Informix.IfxException: ERROR [HY000] [Informix .NET provider]General error.
at IBM.Data.Informix.IfxConnection.GetConnectAttr(SQL_ATTR attribute, HANDLER handler)
at IBM.Data.Informix.IfxConnection.ConnectionIsAlive()
at IBM.Data.Informix.IfxConnectionPool.BindNodeToConnection(IfxConnPoolNode poolNode, IfxConnection connection, ConnectionPoolType ConnPoolType)
at IBM.Data.Informix.IfxConnectionPool.Open(IfxConnection connection)
at IBM.Data.Informix.IfxConnPoolManager.Open(IfxConnection connection)
at IBM.Data.Informix.IfxConnection.Open()
IBM.Data.Informix.dll version is 3.00.06000.2.
This was tested on Windows 7 (32 and 64 bits) and 2008 (64 bits).