I have a connection class that handles my Informix database queries. It has two functions; one to perform simple queries, and one to return a datatable. Intermittently (especially when I let the session sit for a bit, such as ten minutes) I'll get an abandoned mutex error on the conn.open command when requesting new info.
Here is the code in question:
public DataTable CallDtQuery(string query)
{
DataTable dt = new DataTable();
using (IBM.Data.Informix.IfxConnection conn = new
IBM.Data.Informix.IfxConnection(sqlConnection))
{
try
{
IBM.Data.Informix.IfxDataAdapter adapter = new IfxDataAdapter();
adapter.SelectCommand = new IBM.Data.Informix.IfxCommand(query, conn);
conn.Open(); //Error location.
adapter.Fill(dt);
conn.Close();
}
catch (IBM.Data.Informix.IfxException ex)
{
LogError(ex, query);
SendErrorEmail(ex, query);
DisplayError();
}
}
return dt;
}
Additionally, here is the simple query function, which is the only other function in the application that connects to the database:
public string CallSimpleQuery(string query, string command)
{
string result = "";
using (IBM.Data.Informix.IfxConnection conn = new
IBM.Data.Informix.IfxConnection(sqlConnection))
{
try
{
IBM.Data.Informix.IfxDataAdapter adapter = new IfxDataAdapter();
conn.Open();
switch (command)
{
case "UPDATE":
adapter.UpdateCommand = new IBM.Data.Informix.IfxCommand(query, conn);
result = adapter.UpdateCommand.ExecuteNonQuery().ToString();
break;
case "DELETE":
adapter.DeleteCommand = new IBM.Data.Informix.IfxCommand(query, conn);
result = adapter.DeleteCommand.ExecuteNonQuery().ToString();
break;
case "SELECT":
adapter.SelectCommand = new IBM.Data.Informix.IfxCommand(query, conn);
result = adapter.SelectCommand.ExecuteScalar().ToString();
break;
case "INSERT":
adapter.InsertCommand = new IBM.Data.Informix.IfxCommand(query, conn);
result = adapter.InsertCommand.ExecuteNonQuery().ToString();
break;
}
conn.Close();
}
catch (IBM.Data.Informix.IfxException ex)
{
LogError(ex, query);
SendErrorEmail(ex, query);
DisplayError();
}
}
return result;
}
Here is the error generated:
Error Message = The wait completed due to an abandoned mutex.
Message Source:
mscorlib
=============================
Message Target:
Boolean WaitOne(Int64, Boolean)
=============================
Stack Trace:
at System.Threading.WaitHandle.WaitOne(Int64 timeout, Boolean exitContext)
at System.Threading.WaitHandle.WaitOne(Int32 millisecondsTimeout, Boolean exitContext)
at System.Threading.WaitHandle.WaitOne()
at IBM.Data.Informix.IfxConnPoolManager.GetPool(IfxConnSettings key)
at IBM.Data.Informix.IfxConnPoolManager.Open(IfxConnection connection)
at IBM.Data.Informix.IfxConnection.Open()
at XXX.Connections.CallDtQuery(String query) in d:\Inetpub\wwwroot\intranet\CWSheet-test2\App_Code\Connections.cs:line 75
at XXX.details.Page_Load(Object sender, EventArgs e) in d:\Inetpub\wwwroot\intranet\CWSheet-test2\Details.aspx.cs:line 29
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
When the error occurs, instead of going into the catch block and running the Log, Send, and Display error functions, it instead drops into the Application_Error block on the global.asax. Since everything is wrapped inside the try/catch block, I'm not sure what could cause this. Additionally, for whatever reason the application hangs on the CallDtQuery on occasion. I'll be flipping through pages of records in a formview and it will suddenly hang on the CallDtQuery request. Sometimes it might go through after a minute or two, and sometimes it will hang indefinitely until the application times out after 30 minutes.
I've been reading a bit about mutex, but have not ever used it before. Any mutex being used is being generated automatically by the ASP.NET application. With that in mind, I'm not really sure how to troubleshoot or resolve this issue. Any suggestions?
So it turns out the issue was with the IBM.Data.Informix.dll version I was using (2.90.) I found documentation explaining the issue here: http://www.iiug.org/forums/development-tools/index.cgi/read/109
Once I updated to a newer version (3.50), the Abandoned Mutex errors went away. The intermittent hang issue also disappeared as well.
Well, assuming you're not doing any weird threading stuff there are several things to consider
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With