Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySqlClient blacklisting server in ServerPool

Tags:

c#

database

mysql

Is there anything in the .NET MySqlClient (6.9.5.0) where when a MySQL server in the server pool is not responding (possibly due to temporary network issues), the server gets blacklisted or bypassed permanently? In our logging, we notice that an authentication error is thrown:

MySql.Data.MySqlClient.MySqlException (0x80004005): Authentication to host '<HOST>' for user '<USER>' using method 'mysql_native_password' failed with message: Reading from the stream has failed. ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Reading from the stream has failed. ---> System.IO.EndOfStreamException: Attempted to read past the end of the stream.

Immediately after this error occurs, every attempt to write or read from the database fails, with this error message:

MySql.Data.MySqlClient.MySqlException (0x80004005): No available server found.

Any ideas? When the DB server was moved to be on the same host that our application is running on, the problem no longer occurs.

like image 373
Tim Avatar asked Jan 23 '15 15:01

Tim


1 Answers

Two things strike me here:

  1. The nature of your exception: System.IO.EndOfStreamException: Attempted to read past the end of the stream.

  2. And the fact that when the DB is located on the same machine as the calling application, you do not encounter the issue.

To me, that's telling me that a transport or network related error is occurring, which is interrupting your stream. Once that occurs, your connection is reset, so subsequent calls to the DB are failing.

I would try to catch the EndOfStreamException, and attempt to gracefully close and reopen the connection. Something like below. If this allows subsequent calls to succeed, then you've found the issue... although keep in mind that in this structure the original call (within the try block) does not get called again. You will also need to properly need to recreate and open your connection on before making subsequent calls, since it is now always being disposed in the finally block.

try
{
    //your work
}
catch (System.IO.EndOfStreamException ex)
{
    System.Diagnostics.Debug.WriteLine("Stream exception caught: " + ex.Message.ToString());


}
finally
{
    if(myConnection != null)
    {
        myConnection.Close();
        myConnection.Dispose();
    }
}
like image 136
HBomb Avatar answered Oct 09 '22 08:10

HBomb