[CONJ-700] autoReconnect=true on Basic Failover doesn't reconnect Created: 2019-04-21  Updated: 2019-06-13  Resolved: 2019-06-03

Status: Closed
Project: MariaDB Connector/J
Component/s: Failover
Affects Version/s: 2.4.1
Fix Version/s: 2.4.2

Type: Bug Priority: Major
Reporter: William Chiquito Assignee: Diego Dupin
Resolution: Fixed Votes: 1
Labels: Basic-Failover, autoReconnect
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?.


Generated at Thu Feb 08 03:17:40 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.