aws / aws-advanced-jdbc-wrapper

The Amazon Web Services JDBC Driver has been redesigned as an advanced JDBC wrapper. This wrapper is complementary to and extends the functionality of an existing JDBC driver to help an application take advantage of the features of clustered databases such as Amazon Aurora.
Apache License 2.0
216 stars 44 forks source link

Unexpected Transaction State Error on Repeated setReadOnly Calls in AWS Aurora Wrapper #1168

Open erie0210 opened 5 days ago

erie0210 commented 5 days ago

Describe the bug

In an environment using the AWS wrapper driver, we've encountered an intermittent error where calling setReadOnly at the start or end of a transaction triggers the Aurora wrapper's topology, resulting in the error: "Cannot change transaction read-only property in the middle of a transaction."

Expected Behavior

If not strictly necessary, we recommend that the setReadOnly function should avoid executing the topology call, or that the topology function be executed only after the connection is fully established.

What plugins are used? What other connection properties were set?

failover,efm

Current Behavior

Based on our direct analysis of the methods, we’ve inferred the following:

Given these points, we hypothesize that the error occurs in the following sequence:

  1. Transaction ends.
  2. TransactionState changes to IDLE.
  3. Under certain conditions, a topology query is executed.
  4. TransactionState changes back to OPEN.
  5. setReadOnly method is called.
  6. Error occurs.

Reproduction Steps

When the setReadOnly function is executed repeatedly, the error described above occasionally occurs.

Possible Solution

I’d like to propose that the Aurora wrapper driver don't trigger the topology call by default when setReadOnly is invoked.

Referencing the code in question: SubscribedMethodHelper.java, line 59.

Additional Information/Context

I'd be happy to create a PR to help fix this issue :)

The AWS Advanced JDBC Driver version used

2.2.3

JDK version used

correctto-17 17.0.9

Operating System and version

macOS 15.0.1 (24A348)

erie0210 commented 4 days ago

Thank you for the PR above, although it was submitted by someone not directly related to me. I wanted to talk over about this issue if this behavior was intended or not. And why Connection.setReadOnly was included in METHODS_REQUIRING_UPDATED_TOPOLOGY list. Thanks for reviewing this issue.

sergiyvamz commented 4 days ago

Hi @erie0210

Thank you for reaching out and raising this issue. We'll take a look at this and keep you updated as we investigate.

Would you be able to provide driver logs that shows a stack trace of the issue? If it's possible, could you also provide a sample app that reproduces the issue?

As a possible solution for the reported issue, we can suggest to replace failover plugin by failover2. This new failover2 plugin doesn't use driver connection to update a cluster topology, so it can't cause any side effects on a current transaction.

https://github.com/aws/aws-advanced-jdbc-wrapper/blob/main/docs/using-the-jdbc-driver/using-plugins/UsingTheFailover2Plugin.md