Bug #7108 Apparent problem with connection pooling
Submitted: 8 Dec 2004 16:39 Modified: 10 Dec 2004 20:05
Reporter: Chris Sigrist Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S1 (Critical)
Version:1.0.2 OS:Windows (Windows Server 2003)
Assigned to: Reggie Burnett CPU Architecture:Any

[8 Dec 2004 16:39] Chris Sigrist
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.
[9 Dec 2004 18:46] Chris Sigrist
Interestingly enough, simply by switching back to ByteFX v0.7.6.15073 and making no other changes, all the problems are solved.  No connection errors at all.  Something seems very buggy with v1.0.2.
[10 Dec 2004 20:05] Reggie Burnett
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments
to the original bug instead.

Thank you for your interest in MySQL.

Additional info:

I marked this as a dupe since I think it is the same bug as #6634