code: public void preExecute() throws SQLException {
      lastQueryNanos = System.nanoTime();
      //if connection is closed or failed on slave
      if (this.currentProtocol != null && this.currentProtocol.isClosed()) {
        preAutoReconnect();
      }
    }
docs: Before executing query, reconnect if connection is closed, and autoReconnect option is set.
  
  @throws SQLException if connection has been explicitly closed.