shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

An error occurs when using XA transactions:java.lang.NullPointerException

Open zhong2312 opened this issue 1 year ago • 0 comments

version:5.3.2

Debug:

After the execution of the init method in XAShardingSphereTransactionManager, the subsequent execution will involve the close method. Inside the close method, the cachedDataSources.clear() operation will be performed.

init, note the object ID @8060 image

In the close method, the cachedDataSources of the object with ID @8060 is cleared. image

When invoking the getConnection method at this point, the cachedDataSources is empty. image

Then an error occurs. image

The ZookeeperRepository listens for configuration changes and then triggers ShardingSphereTransactionManagerEngine.close. image

If I comment out the watch code, the program can run normally without any errors. image

stack trace: Caused by: java.lang.NullPointerException at org.apache.shardingsphere.transaction.xa.XAShardingSphereTransactionManager.getConnection(XAShardingSphereTransactionManager.java:91) at org.apache.shardingsphere.transaction.ConnectionTransaction.getConnection(ConnectionTransaction.java:106) at org.apache.shardingsphere.driver.jdbc.core.connection.ConnectionManager.createConnection(ConnectionManager.java:365) at org.apache.shardingsphere.driver.jdbc.core.connection.ConnectionManager.createConnections(ConnectionManager.java:334) at org.apache.shardingsphere.driver.jdbc.core.connection.ConnectionManager.getConnections(ConnectionManager.java:323) at org.apache.shardingsphere.infra.executor.sql.prepare.driver.DriverExecutionPrepareEngine.group(DriverExecutionPrepareEngine.java:88) at org.apache.shardingsphere.infra.executor.sql.prepare.AbstractExecutionPrepareEngine.prepare(AbstractExecutionPrepareEngine.java:65) at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.createExecutionGroupContext(ShardingSpherePreparedStatement.java:533) at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.useDriverToExecute(ShardingSpherePreparedStatement.java:508) at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.execute(ShardingSpherePreparedStatement.java:443)

zhong2312 avatar Jul 04 '23 11:07 zhong2312