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

Connections sometimes don't respect setCatalog

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 2.4.4, 2.5.4
    • 2.6.0
    • aurora, Failover
    • None
    • AWS Aurora RDS with 1 replica

    Description

      We have a multi-tenant DataSource implementation, which wraps HikariCP pools and calls setCatalog on connect, like so:

      @Override
      public Connection getConnection() throws SQLException {
        DataSource ds = getHikariDs(...);
        Connection conn = ds.getConnection();
        conn.setCatalog(...);
        return conn;
      }
      

      What I'm seeing is sporadic SQL errors indicating a connection is using the default database (from the url) and not the one specified in setCatalog. In debugging, I see that the connection with the error is different than the one created, leading me to think it's an issue with secondary protocol. This seems to happen with Spring MVC controller methods marked as @Transactional(readOnly=true).

      I found in reading the source a questionable condition which potentially might be leading to this issue, in MastersSlavesListener:: lockAndSwitchSecondary(): https://github.com/mariadb-corporation/mariadb-connector-j/blob/master/src/main/java/org/mariadb/jdbc/internal/failover/impl/MastersSlavesListener.java#L648

          // if asked to be on read only connection, switching to this new connection
          if (currentReadOnlyAsked
              || (urlParser.getOptions().failOnReadOnly && !currentReadOnlyAsked && isMasterHostFail())) {
      >>>      if (currentProtocol == null) {    <<<
              try {
                syncConnection(currentProtocol, newSecondaryProtocol);
              } catch (Exception e) {
                // Some error append during connection parameter synchronisation
              }
            }
            currentProtocol = newSecondaryProtocol;
      

      I am thinking that line should rather be " if (currentProtocol != null) ", so that the syncConnection() call can properly copy the database into the newSecondaryProtocol?

      Attachments

        Activity

          People

            diego dupin Diego Dupin
            jstehler Jared Stehler
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.