Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDBC Driver still throwing XAException with error code XAER_RMERR on AG failover. #2130

Closed
djmatthews opened this issue May 18, 2023 · 1 comment · Fixed by #2132
Closed
Labels
Question Used when a question is asked, as opposed to an issue being raised
Projects

Comments

@djmatthews
Copy link

Driver version

The JDBC driver version is 12.3.0 Preview Release

SQL Server version

SQL Server AG 2017

Client Operating System

Windows Server 2016, version 10.0

JAVA/JVM version

Java version = 1.8.0_171, Java Runtime Version = 8.0.5.17 - pxa6480sr5fp17ifix-20180726_01(SR5 FP17+IJ08001)

Table schema

Problem description

This is a follow on from #1432
Despite having the fix for 1432 (#2078) the same behaviour occurred ie the JDBC driver reported an XAER_RMERR when it should have reported an XAER_RMFAIL resulting in indoubt transactions remaining in SQLServer during failover from AG primary to secondary.

Expected behavior

JDBC driver should have thrown an XAException with errorCode XAER_RMFAIL

Actual behavior

JDBC driver throws XAException with errorCode XAER_RMERR

Error message/stack trace

Complete error message and stack trace.

Here is a callstack showing the XAException on the XA commit:

[5/15/23 20:05:33:883 UTC] 00000160 WSRdbXaResour < commit Exit
javax.transaction.xa.XAException: com.microsoft.sqlserver.jdbc.SQLServerException: Connection reset
at com.microsoft.sqlserver.jdbc.SQLServerXAResource.dtc_XA_interface(SQLServerXAResource.java:773)
at com.microsoft.sqlserver.jdbc.SQLServerXAResource.commit(SQLServerXAResource.java:839)
at com.ibm.ws.rsadapter.spi.WSRdbXaResourceImpl.commit(WSRdbXaResourceImpl.java:361)
at com.ibm.ejs.j2c.XATransactionWrapper.commit(XATransactionWrapper.java:496)
at com.ibm.tx.jta.impl.JTAXAResourceImpl.commit(JTAXAResourceImpl.java:308)
at com.ibm.tx.jta.impl.RegisteredResources.deliverOutcome(RegisteredResources.java:1644)
at com.ibm.tx.jta.impl.RegisteredResources.distributeOutcome(RegisteredResources.java:2003)
at com.ibm.tx.jta.impl.RegisteredResources.distributeCommit(RegisteredResources.java:2315)
at com.ibm.tx.jta.impl.TransactionImpl.internalCommit(TransactionImpl.java:1879)
at com.ibm.tx.jta.impl.TransactionImpl.internalCommit(TransactionImpl.java:1855)
at com.ibm.tx.jta.impl.TransactionImpl.coreStage2CommitProcessing(TransactionImpl.java:1135)
at com.ibm.tx.jta.impl.TransactionImpl.stage2CommitProcessing(TransactionImpl.java:1173)
at com.ibm.tx.jta.impl.TransactionImpl.processCommit(TransactionImpl.java:1034)
at com.ibm.tx.jta.impl.TransactionImpl.commit(TransactionImpl.java:964)
at com.ibm.ws.tx.jta.TranManagerImpl.commit(TranManagerImpl.java:439)
...
When the errorCode is checked:
[5/15/23 20:05:33:884 UTC] 00000160 RegisteredRes 3 XAException: error code XAER_RMERR

Any other details that can be helpful

Call stack in com.microsoft.sqlserver.jdbc.SQLServerXAResource shows that the driver contains the fix for issue 1432
It looks from the code change in the PR that the Exception handling to treat the error as an XAER_RMFAIL needs to include the case where the "Connection Reset" SQLServerException occurs. Moreover, I think it is arguable that by default the Exception handlilng should throw XAER_RMFAIL with XAER_RMERR only thrown if the specific error warrants it since XAER_RMERR is a much more specific error (with specific semantics in the XA Spec) than XAER_RMFAIL is - the JDBC driver code currently does the opposite (assuming that it will throw an XAER_RMERR unless the specifics of the error are determined to be XAER_RMFAIL).

JDBC trace logs

@tkyc
Copy link
Member

tkyc commented May 18, 2023

Moreover, I think it is arguable that by default the Exception handlilng should throw XAER_RMFAIL with XAER_RMERR only thrown if the specific error warrants it since XAER_RMERR is a much more specific error (with specific semantics in the XA Spec) than XAER_RMFAIL is - the JDBC driver code currently does the opposite (assuming that it will throw an XAER_RMERR unless the specifics of the error are determined to be XAER_RMFAIL).

Fair point, and it was brought up in our team's discussions. But, It would be quite difficult to determine for all server level errors whether it would be appropriate to throw XAER_RMERR or XAER_RMFAIL. So, we opt to only change what we for sure know should throw XAER_RMFAIL.

@lilgreenbird lilgreenbird added this to Under Investigation in MSSQL JDBC via automation May 18, 2023
@lilgreenbird lilgreenbird added the Question Used when a question is asked, as opposed to an issue being raised label May 18, 2023
@lilgreenbird lilgreenbird linked a pull request May 24, 2023 that will close this issue
MSSQL JDBC automation moved this from Under Investigation to Closed Issues May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Used when a question is asked, as opposed to an issue being raised
Projects
MSSQL JDBC
  
Closed Issues
Development

Successfully merging a pull request may close this issue.

3 participants