Bug #72467 MySQL Connector/Net Failover
Submitted: 27 Apr 2014 16:56 Modified: 25 Sep 2016 7:35
Reporter: Gregorio Barberio Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S1 (Critical)
Version:6.8.3 OS:Any
Assigned to: CPU Architecture:Any
Tags: Replication Manager; Failover support

[27 Apr 2014 16:56] Gregorio Barberio
Description:
As reported at the following link:
https://blogs.oracle.com/MySqlOnWindows/entry/how_to_using_replication_load
The MySql Connector/Net supports Failover monitoring connections to the servers, redirecting load to available servers on each request. 
Using the Load Balancing feature of the Connector/Net with a MySql Cluster configured with two master node (IsMaster=true for both nodes), the system throw an unexpected exception (Unable to connect to any of the specified mysql hosts).

How to repeat:
To reproduce the behaviour, the sample code (available to the link
https://blogs.oracle.com/MySqlOnWindows/entry/how_to_using_replication_load)
was implemented with the following changes and in the scenario reported below:
Changes:
Both servers has the flag IsMaster="true".
Scenario:
A MySql cluster configured on a single test machine with 2 data nodes, 2 mysqld nodes and a mysql management node.

The sample works when all nodes are ups, stopping a mysqld node and restarting the sample, the exception "Unable to connect to any of the specified mysql hosts" was throw.

Suggested fix:
The problem appears to be in the ReplicationManager class in the method GetNewConnection.

The following code:
Driver driver = Driver.Create(new MySqlConnectionStringBuilder(server.ConnectionString));
throw an exception when a server is not available and the Exception is not catched locally.
In my scenario never starts the BackgroundWorker responsible to monitor the connection status because the exception were catched by the client. 

I have tried the following solution
**** replace this code
        //Driver driver = Driver.Create(new MySqlConnectionStringBuilder(server.ConnectionString));

        //if (connection.driver == null

        //  || driver.Settings.ConnectionString != connection.driver.Settings.ConnectionString)
        //{
        //    connection.Close();
        //    connection.hasBeenOpen = false;
        //    try
        //    {
**** end replace this code
**** with
       Driver driver = null;
        try
        {
            driver = Driver.Create(new MySqlConnectionStringBuilder(server.ConnectionString));
        }
        catch { }
        if (connection.driver == null
          || driver == null
          || driver.Settings.ConnectionString != connection.driver.Settings.ConnectionString)
        {
            connection.Close();
            connection.hasBeenOpen = false;
            try
            {
                if (driver == null)
                    throw new Exception("");
**** end with
Another small change was the removing of the following line
elapsedEvent(sender, null);
that force a check of connection just after the error.
[27 Apr 2014 18:59] Gregorio Barberio
Adding the following two brakpoint in ReplicationManager:
bool isRunning = false;
isRunning = true;

with one server available, after a while the Exception "No available server found." occurs, I think there is necessary a better way to manipulate server variable in a thread safe manner.
Probably the server checked on the line:
using (MySqlConnection connectionFailed = new MySqlConnection(server.ConnectionString))
is not the right one.
[28 Apr 2014 10:28] Gregorio Barberio
The bug impacts every system capable of running the Connector / Net.
[2 Aug 2016 12:17] Chiranjeevi Battula
Hello Gregorio Barberio,

Thank you for the bug report.
I tried to reproduce the issue at my end using MySQL Connector/Net 6.9.9 but not seeing any issues in connections.
Could you please try with latest version of MySQL Connector/Net and let us know if you are still having the issue.

Thanks,
Chiranjeevi.
[3 Sep 2016 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[25 Sep 2016 7:35] Gregorio Barberio
Hi Chiranjeevi Battula,
I tried the new MySql Connector NET version 6.9.9 and the bug appears to be solved. Exploring the source code I have seen some changes in the ReplicationManager.cs.
I will investigate further.
Gregorio