Bug #84098 endless loop in LoadBalancedAutoCommitInterceptor
Submitted: 8 Dec 2016 2:26 Modified: 26 Sep 2019 17:10
Reporter: zhangyz zhang Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:5.1.39 OS:Any
Assigned to: CPU Architecture:Any
Tags: LoadBalancedAutoCommitInterceptor endless loop

[8 Dec 2016 2:26] zhangyz zhang
Description:
when set the parameter "loadBalanceAutoCommitStatementThreshold=2"  in jdbc url
, then the LoadBalancedAutoCommitInterceptor.java will be endless loop in 84~85 line (the version is 5.1.39)

for example:
BasicDataSource ds = new org.apache.commons.dbcp.BasicDataSource();
    	ds.setMaxActive(1);
    	ds.setMaxIdle(1);
    	ds.setMinIdle(1);
    	ds.setValidationQuery("select current_date");
    	ds.setInitialSize(1);
    	ds.setUsername("root");
    	ds.setPassword("......");
    	ds.setDriverClassName("com.mysql.jdbc.ReplicationDriver");
    	ds.setUrl("jdbc:mysql:replication://121.43.235.120:3306,114.215.201.204:3306,121.43.235.120:3306/manfenhomev4?useUnicode=true&characterEncoding=UTF-8&autoReconnect=false&loadBalanceStrategy=random&retriesAllDown=2&loadBalanceAutoCommitStatementThreshold=2&connectTimeout=10000&socketTimeout=20000&readFromMasterWhenNoSlaves=true&allowSlavesDownConnections=true&allowMasterDownConnections=true");
Connection connection = ds.getConnection(); 

This happens when getConnection();

How to repeat:
The Error Stack:

LoadBalancedAutoCommitInterceptor.postProcess(String, Statement, ResultSetInternalMethods, Connection, int, boolean, boolean, SQLException) line: 85	
MysqlIO.invokeStatementInterceptorsPost(String, Statement, ResultSetInternalMethods, boolean, SQLException) line: 2878	
MysqlIO.sqlQueryDirect(StatementImpl, String, String, Buffer, int, int, int, boolean, String, Field[]) line: 2801	
JDBC4Connection(ConnectionImpl).execSQL(StatementImpl, String, int, Buffer, int, int, boolean, String, Field[], boolean) line: 2545	
JDBC4Connection(ConnectionImpl).execSQL(StatementImpl, String, int, Buffer, int, int, boolean, String, Field[]) line: 2503	
JDBC4LoadBalancedMySQLConnection(MultiHostMySQLConnection).execSQL(StatementImpl, String, int, Buffer, int, int, boolean, String, Field[]) line: 164	
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]	
NativeMethodAccessorImpl.invoke(Object, Object[]) line: 57	
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 43	
Method.invoke(Object, Object...) line: 606	
LoadBalancedConnectionProxy.invokeMore(Object, Method, Object[]) line: 492	
LoadBalancedConnectionProxy(MultiHostConnectionProxy).invoke(Object, Method, Object[]) line: 452	
$Proxy0.execSQL(StatementImpl, String, int, Buffer, int, int, boolean, String, Field[]) line: not available	
JDBC4ReplicationMySQLConnection(MultiHostMySQLConnection).execSQL(StatementImpl, String, int, Buffer, int, int, boolean, String, Field[]) line: 164	
StatementImpl.executeQuery(String) line: 1369	
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]	
NativeMethodAccessorImpl.invoke(Object, Object[]) line: 57	
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 43	
Method.invoke(Object, Object...) line: 606	
MultiHostConnectionProxy$JdbcInterfaceProxy.invoke(Object, Method, Object[]) line: 103	
$Proxy2.executeQuery(String) line: not available	
DelegatingStatement.executeQuery(String) line: 208	
PoolableConnectionFactory.validateConnection(Connection) line: 658	
BasicDataSource.validateConnectionFactory(PoolableConnectionFactory) line: 1558
[8 Dec 2016 13:07] Chiranjeevi Battula
Hello zhangyz,

Thank you for the bug report.
Verified based on internal discussion with dev's.

Thanks,
Chiranjeevi.
[26 Sep 2019 17:10] Daniel So
Posted by developer:
 
Added the following entry to the Connector/J 8.0.18 changelog: 

"For a replication setup, when the connection property loadBalanceAutoCommitStatementThreshold was set to any values other than 0, load-balancing server switching failed. It was because in this case, LoadBalancedAutoCommitInterceptor did not have the required access to the top level connection proxy that had established the connection, and this fix enables such access."