Description:
I have been using MySQL Connector/Net in conjunction with MySQL v4.1.7 for about a month. I have been getting repeated errors having to do with aborted connection and forcibly closed connections. All these errors seem to have to do with Connection Pooling. Originally I had my wait_timeout variable set at the default (28800) and was getting the following error at seemingly random times, never consistently:
An existing connection was forcibly closed by the remote host
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
Source Error:
Line 38: Dim strSQL = "SELECT * FROM xxxxxx INNER JOIN xxxxxx ON xxxxxx.xxxxxx = xxxxxx.xxxxxx WHERE xxxxxx='" & xxxxxx & "' AND xxxxxx='" & xxxxxx & "' LIMIT 0,1;"
Line 39: Dim objConnection As New MySqlConnection(vidMailConnString)
Line 40: objConnection.Open()
Line 41: Dim objCommand As New MySqlCommand(strSQL, objConnection)
Line 42: Dim objDataReader As MySQLDataReader
Source File: xxxxxx\login.aspx Line: 40
Stack Trace:
[SocketException (0x2746): An existing connection was forcibly closed by the remote host]
System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) +356
System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size) +102
[IOException: Unable to write data to the transport connection.]
MySql.Data.MySqlClient.MySqlConnection.Open() +149
ASP.login_aspx.logIn(Object sender, EventArgs e) in xxxxxx\login.aspx:40
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1266
--------------------------------------------------------------------------------------------
After tooling around with things, I ended up making the wait_timeout to 360 seconds. Then I began receiving the following error after the connection had timed out:
An established connection was aborted by the software in your host machine
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine
Source Error:
Line 52: Dim strSQL = "SELECT * FROM xxxxxx INNER JOIN xxxxxx ON xxxxxx.xxxxxx = xxxxxx.xxxxxx WHERE xxxxxx='" & xxxxxx & "' AND xxxxxx='" & xxxxxx & "' LIMIT 0,1;"
Line 53: Dim objConnection As New MySqlConnection(vidMailConnString)
Line 54: objConnection.Open()
Line 55: Dim objCommand As New MySqlCommand(strSQL, objConnection)
Line 56: Dim objDataReader As MySQLDataReader
Source File: xxxxxx\login.aspx Line: 54
Stack Trace:
[SocketException (0x2745): An established connection was aborted by the software in your host machine]
System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) +356
System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size) +102
[IOException: Unable to write data to the transport connection.]
MySql.Data.MySqlClient.MySqlConnection.Open() +149
ASP.login_aspx.logIn(Object sender, EventArgs e) in xxxxxx\login.aspx:54
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1266
--------------------------------------------------------------------------------------------
Although both the errors above reference the same page, these errors were popping up all over the site.
The code used in this site is very similar to other code used for other sites and has been checked for accuracy. All connections are closed properly after executing. The only difference is the versions of the Connector/Net and the MySQL version. Until now, I have been using ByteFX v0.7.6 and MySQL v4.0.X.
Additonally, my datasource references "localhost" as the database.
TO RESOLVE this issue, I can use the string "pooling=false" in the connection string but this effectively doubles the resources it takes to run DB queries.
How to repeat:
The first error, "An existing connection was forcibly closed by the remote host" was happening at very random intervals and I was having a hard time repeating it at will.
The second error, "An established connection was aborted by the software in your host machine", seems to occur when making any additional quries on the DB after the a connection has expired due to the wait_timeout variable. Mine is currently set at 360 seconds.
Suggested fix:
From the outside looking in, it appears that these problems are happening when Connector/Net tries to connect to an existing connection that has been terminated. Rather than gracefully handling then unexpected situation of the connection not being there and making a new connection, it throws an exception.
None of the DB calls that I am making need persistant connections. They open, do their thing, and then close. These routines are all exclusive of one another and should be able to open different connections if none are in the pool. It seems that instead, they are generating errors.