Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
2.4.4, 2.5.4
-
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?