]
Ivo Studensky moved WFLY-12316 to JBJCA-1391:
---------------------------------------------
Project: IronJacamar (was: WildFly)
Key: JBJCA-1391 (was: WFLY-12316)
Workflow: classic default workflow (was: GIT Pull Request workflow )
Component/s: JDBC
(was: JCA)
SQLException.getSQLState() and getCause() are null with XADatasource
connection for postgresql during network failure
---------------------------------------------------------------------------------------------------------------------
Key: JBJCA-1391
URL:
https://issues.jboss.org/browse/JBJCA-1391
Project: IronJacamar
Issue Type: Bug
Components: JDBC
Reporter: Ivo Studensky
Assignee: Ivo Studensky
Priority: Major
When using staled connection of xa datasource, the connection throws SQLException.
Then SQLException.getSQLState() and getCause() returns null if using XA datasource.
The SQLException is re-created in the following stack.
{code}
#####: java.sql.SQLException: Error
at
org.jboss.jca.adapters.jdbc.WrappedConnection.checkException(WrappedConnection.java:2033)
at
org.jboss.jca.adapters.jdbc.WrappedStatement.checkException(WrappedStatement.java:1436)
at
org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:509)
at com.example.SelectXaServlet.doGet(SelectXaServlet.java:41)
{code}
- adapters/src/main/java/org/jboss/jca/adapters/jdbc/WrappedConnection.java
{code}
protected SQLException checkException(Throwable t) throws SQLException
{
Throwable result = null;
if (t instanceof AbstractMethodError)
{
t = new SQLFeatureNotSupportedException(bundle.methodNotImplemented(), t);
}
if (mc != null)
result = mc.connectionError(t);
if (result instanceof SQLException)
{
throw (SQLException) result;
}
else
{
throw new SQLException("Error", result); // If the managed connection
is null, create a new SQLException.
}
}
{code}
In the above, the managed connection is null.
This is because that the ConnectionEventListener#connectionErrorOccurred() fired by the
Postgresql driver.
(oracle driver doesn't fire the event during executing statement, so this issue
doen't occur.)
{code}
at
org.jboss.jca.adapters.jdbc.WrappedConnection.setManagedConnection(WrappedConnection.java:120)
// null set
at
org.jboss.jca.adapters.jdbc.BaseWrapperManagedConnection.cleanup(BaseWrapperManagedConnection.java:339)
- locked <0x00000000f9ea3560> (a java.util.HashSet)
at
org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreConcurrentLinkedDequeManagedConnectionPool.returnConnection(SemaphoreConcurrentLinkedDequeManagedConnectionPool.java:666)
at
org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreConcurrentLinkedDequeManagedConnectionPool.returnConnection(SemaphoreConcurrentLinkedDequeManagedConnectionPool.java:611)
at
org.jboss.jca.core.connectionmanager.pool.AbstractPool.returnConnection(AbstractPool.java:847)
at
org.jboss.jca.core.connectionmanager.AbstractConnectionManager.returnManagedConnection(AbstractConnectionManager.java:725)
at
org.jboss.jca.core.connectionmanager.listener.AbstractConnectionListener.connectionErrorOccurred(AbstractConnectionListener.java:472)
at
org.jboss.jca.adapters.jdbc.BaseWrapperManagedConnection.broadcastConnectionError(BaseWrapperManagedConnection.java:673)
at
org.jboss.jca.adapters.jdbc.xa.XAManagedConnection.broadcastConnectionError(XAManagedConnection.java:203)
at
org.jboss.jca.adapters.jdbc.xa.XAManagedConnection$1.connectionErrorOccurred(XAManagedConnection.java:91)
at
org.postgresql.ds.PGPooledConnection.fireConnectionFatalError(PGPooledConnection.java:183)
at
org.postgresql.ds.PGPooledConnection.fireConnectionError(PGPooledConnection.java:237)
at org.postgresql.ds.PGPooledConnection.access$200(PGPooledConnection.java:38)
at
org.postgresql.ds.PGPooledConnection$StatementHandler.invoke(PGPooledConnection.java:428)
at com.sun.proxy.$Proxy64.executeQuery(Unknown Source)
at
org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:504)
at com.example.SelectXaServlet.doGet(SelectXaServlet.java:41)
{code}
adapters/src/main/java/org/jboss/jca/adapters/jdbc/xa/XAManagedConnection.java
{code}
public XAManagedConnection(XAManagedConnectionFactory mcf, XAConnection xaConnection,
Properties props,
int transactionIsolation, int psCacheSize) throws
SQLException
{
super(mcf, xaConnection.getConnection(), props, transactionIsolation,
psCacheSize);
this.xaConnection = xaConnection;
xaConnection.addConnectionEventListener(new javax.sql.ConnectionEventListener()
{
...<snip>
public void connectionErrorOccurred(javax.sql.ConnectionEvent ce)
{
SQLException ex = ce.getSQLException();
broadcastConnectionError(ex); // cleanup and return this connection
when this event fired.
}
});
{code}