Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-700

autoReconnect=true on Basic Failover doesn't reconnect

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.4.1
    • Fix Version/s: 2.4.2
    • Component/s: Failover
    • Environment:
      Ubuntu 18.04 (OS)
      10.3.14 (MariaDB)
      1.8.0_191/64-Bit (OpenJDK)
      mariadb-java-client-2.4.1 (Driver)

      Description

      Failover and Load Balancing Parameters :: autoReconnect

      When this parameter enabled when a Failover and Load Balancing Mode is not in use, the connector will simply try to reconnect to its host after a failure. This is referred to as Basic Failover.

      import java.sql.*;
      import java.util.Properties;
       
      public class JDBCExample {
        static final String DB_URL = "jdbc:mariadb://myip:myport/mydb";
        static final String USER = "myuser";
        static final String PASS = "mypass";
       
        public static void main(String[] args) {
          Properties props = new Properties();
          props.put("user", USER);
          props.put("password", PASS);
          props.put("autoReconnect", "true");
       
          try (Connection conn =
                    DriverManager.getConnection(DB_URL, props)) {
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery("SELECT 1;");
       
            stmt.execute("SET SESSION wait_timeout = 1;");
            Thread.sleep(3000); // or restart MariaDB Server
       
            try {
              rs = stmt.executeQuery("SELECT 1;");
              System.out.println("1");
            } catch (SQLException e) {
              System.out.println("2");
            } finally {
              rs.close();
              stmt.close();
              conn.close();
            }
          } catch (SQLException se) {
            se.printStackTrace();
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
      }
      

      According to the documentation, the expected result should be 1 (reconnect), however, it's 2. Why doesn't the driver reconnect?.

        Attachments

          Activity

            People

            Assignee:
            diego dupin Diego Dupin
            Reporter:
            wchiquito William Chiquito
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: